acts_as_list“NoMethodError(xxx的未定义方法`position_was')”

时间:2013-12-03 21:30:49

标签: ruby-on-rails best-in-place acts-as-list

我正在尝试使用theme_name更新Best In Place。但是,目前它会抛出一个错误:

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

我有一个名为fruit的资源和一个名为theme的资源。 fruit属于themethemefruit。使用getter和setter方法通过fruit设置主题:

#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

我现在还提到themefruit都属于conversationfruit资源acts_as_list

这是fruits_controller.rb中的更新操作,它只响应JSON

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

    respond_with_bip(@fruit)
  end

使用best_in_place更新,我收到错误消息。以下是开发控制台的完整输出:

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'

任何输入都将不胜感激。如果我没有在任何地方解释自己,请告诉我,以便我可以修改它!

编辑:

Here's指向上下文的github页面的链接。

1 个答案:

答案 0 :(得分:1)

这是因为没有列'位置'。我正在使用排名。这就是act_as_list调用应该是这样的:

acts_as_list column: :rank, scope: :conversation