我有一个带有属性“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
rota 的架构是:
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