2012-03-10 48 views
0

合併後,我的RoR 3項目不再'正確創建'。默認屬性得到正確設置,而不是那些我在傳:rails 3創建設置值以開票

1.9.3-p125 :020 > f=Ifilter.create(:name => "test2", :regex => "()") 
SQL (101.5ms) INSERT INTO "ifilters" ("created_at", "name", "regex", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Sat, 10 Mar 2012 03:36:24 UTC +00:00], ["name", nil], ["regex", nil], ["updated_at", Sat, 10 Mar 2012 03:36:24 UTC +00:00]] 

=> #<Ifilter id: 2, name: nil, regex: nil, created_at: "2012-03-10 03:36:24", updated_at: "2012-03-10 03:36:24"> 

不過,保存仍然有效:

1.9.3-p125 :021 > f=Ifilter.new 
=> #<Ifilter id: nil, name: nil, regex: nil, created_at: nil, updated_at: nil> 
1.9.3-p125 :022 > f.name = "test" 
=> "test" 
1.9.3-p125 :023 > f.regex = "()" 
=> "()" 
1.9.3-p125 :024 > f.save 
    SQL (4.8ms) INSERT INTO "ifilters" ("created_at", "name", "regex", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Sat, 10 Mar 2012 04:13:10 UTC +00:00], ["name", "test"], ["regex", "()"], ["updated_at", Sat, 10 Mar 2012 04:13:10 UTC +00:00]] 
=> true 

這是怎麼回事?

謝謝!

+0

您如何定義模型? – 2012-03-10 04:52:13

+0

只是完全標準 - 導軌生成腳手架ifilter名稱:字符串正則表達式:字符串。沒有什麼可以合併到ifilter中,但框架中的東西可能已經更新。 – 2012-03-10 05:39:00

回答

0

看起來你可能有你的模型attr_accessiblehttp://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html#method-i-attr_accessible

如果你正在使用它,沒有被明確列出的屬性也不會經由#new#create#update_attributes設定(和幾個)。

+0

這工作!添加 - attr_accessible:name,:regex - 我的iFilter模型,並且事情再次變好。看起來有人升級了我們網站上的安全資料。 :) – 2012-03-10 05:39:55

0

這通常發生在啓用屬性白名單時。請確保您通過宏指令attr_accessible在模型中定義可通過質量分配設置的屬性:

class Ifilter 
    attr_accessible :name, :regex 
    ... 
end