acts_as_list "NoMethodError (undefined method `position_was' for xxx)"

1.5k views Asked by At

I'm trying to update the theme_name using Best In Place. At the moment however, it throws an error:

NoMethodError (undefined method `position_was' for #<Fruit:0x000000037e80a8>):
  app/controllers/fruits_controller.rb:18:in `update'

I have a resource called fruit and one called theme. fruit belongs to theme and theme has many fruit. Themes are set through fruit using getter and setter methods:

#fruit.rb
  def theme_name
    theme.try(:name)
  end

  def theme_name= name
    self.theme = Theme.find_or_create_by(name: name) if name.present?
    self.theme.conversation_id = self.conversation_id
  end

I also mention now that both themes and fruit belong to conversation. The fruit resource acts_as_list.

This is the update action in fruits_controller.rb, it only responds to JSON

  def update
    @fruit = Fruit.find(params[:id])
    @fruit.update_attributes(fruit_params)

    respond_with_bip(@fruit)
  end

Using the best_in_place update I get the error. Here is the full output from the dev console:

Started PUT "/fruits/12" for 127.0.0.1 at 2013-12-03 20:32:57 +0000
Processing by FruitsController#update as JSON
  Parameters: {"fruit"=>{"theme_name"=>"Candy"}, "authenticity_token"=>"UdsIgUglpPjkD5PS64PCxV9JyJFLlNxrO3tg8E9oe8o=", "id"=>"12"}
  Fruit Load (0.3ms)  SELECT "fruits".* FROM "fruits" WHERE "fruits"."id" = ? LIMIT 1  [["id", "12"]]
   (0.1ms)  begin transaction
  Theme Load (0.1ms)  SELECT "themes".* FROM "themes" WHERE "themes"."name" = 'Candy' LIMIT 1
  SQL (0.7ms)  INSERT INTO "themes" ("created_at", "name", "updated_at") VALUES (?, ?, ?)  [["created_at", Tue, 03 Dec 2013 20:32:57 UTC +00:00], ["name", "Candy"], ["updated_at", Tue, 03 Dec 2013 20:32:57 UTC +00:00]]
  SQL (0.4ms)  UPDATE "fruits" SET "theme_id" = ?, "updated_at" = ? WHERE "fruits"."id" = 12  [["theme_id", 1], ["updated_at", Tue, 03 Dec 2013 20:32:57 UTC +00:00]]
   (0.2ms)  rollback transaction
Completed 500 Internal Server Error in 31ms

NoMethodError (undefined method `position_was' for #<Fruit:0x000000037e80a8>):
  app/controllers/fruits_controller.rb:18:in `update'

Any input would be greatly appreciated. If I have failed to explain myself anywhere please let me know so I can amend it!

Edit:

Here's a link to the github page for context.

1

There are 1 answers

0
Jragon On BEST ANSWER

This is because there's no column 'Position'. I was using rank instead. This is what the act_as_list call should have looked like:

acts_as_list column: :rank, scope: :conversation