0

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を持っています。テーマは、getter メソッドと setter メソッドを使用して設定されます。themefruitfruit

#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また、 との両方が に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 ページへのリンクを次に示します

4

1 に答える 1

1

これは、「位置」という列がないためです。代わりにランクを使用していました。act_as_list呼び出しは次のようになります。

acts_as_list column: :rank, scope: :conversation
于 2013-12-18T22:47:47.767 に答える