0

属性「turn_index」を持つ「rota」モデルがあります。何らかの理由で、update_attributes が機能していないようです。理由はありますか?

  rota = Rota.create
  rota.turn_index.should == 0 -- passes
  rota.update_attributes(:turn_index=>1)
  rota.turn_index.should == 1 -- fails

勤務表のスキーマは次のとおりです。

  create_table "rotas", :force => true do |t|
    t.string   "name"
    t.integer  "turn_index"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
  end

ロタ モデル:

class Rota < ActiveRecord::Base
  has_many :rotazations
  has_many :users, :through => :rotazations
  has_many :invitations

  before_save :set_turn_index

  private

  def set_turn_index
    self.turn_index = 0
  end
end
4

2 に答える 2

0

で、 0にbefore_save設定しています。これは、作成時に設定するだけで修正できます。turn_index

before_save :set_turn_index, on: :create

turn_indexまたは、移行でデフォルト値を0に設定します。

于 2012-05-05T15:36:16.330 に答える
0

あなたbefore_saveは常にturn_index0に設定しています

于 2012-05-05T15:33:48.727 に答える