2012-05-05 15 views
0

私は、属性 "turn_index"を持つ "rota"モデルを持っています。何らかの理由で、update_attributesが機能していないようです。任意の手掛かりはなぜですか?Rails:単純な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 
+0

ロータモデルはどのように見えますか? – natedavisolds

+0

更新された質問 – Karan

答えて

0

0に、あなたはturn_indexを設定しています0に設定してください。これはsettinだけで修正できます

before_save :set_turn_index, on: :create 

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

0

あなたbefore_save常に設定されturn_indexbefore_save

+0

まあまあ、それは信じられない。 – Karan

関連する問題