我正在尝试更新theme_name
使用Best In Place
. 但是,目前它会引发错误:
NoMethodError (undefined method `position_was' for #<Fruit:0x000000037e80a8>):
app/controllers/fruits_controller.rb:18:in `update'
我有一个名为的资源fruit
和一个名为theme
. fruit
属于theme
并theme
拥有许多fruit
. 通过fruit
使用 getter 和 setter 方法设置主题:
#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
我现在还提到theme
s 和fruit
属于conversation
。fruit
资源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'
任何投入将不胜感激。如果我未能在任何地方解释自己,请告诉我,以便我修改!
编辑:
这是github 页面的链接以获取上下文。