开发者

Rails: Form_for fields without corresponding database columns

I'm trying to do up a rails form_for that includes a checkbox for :terms_and_conditions (with validates_presence_of). terms_and_conditions has not been declared as a column in the corresponding database table.

At the moment, when I submit the form and try to create a new model with MyModel.new(params[:mymodel]), I get an *'unknown attribut开发者_如何转开发e: terms_and_conditions'* error.

So, just wondering: how do I run create a field for a column - and run validations on it - without inserting that field into the database?

Many thanks...


You need a virtual attribute for terms_and_conditions in your model. Take a look at this screencast


For accepting T&Cs only, you should now be able to just put this in your model:

validates_acceptance_of :terms_and_conditions
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜