form fields not in schema

6 views
Skip to first unread message

fugee ohu

unread,
Apr 20, 2017, 10:08:58 AM4/20/17
to Ruby on Rails: Talk
I'm putting some fields in my form that the controllers gonna use but they're not columns in the table so I can't validate at the model level? How can I validate them?

batuhan...@gmail.com

unread,
Apr 21, 2017, 2:58:36 AM4/21/17
to Ruby on Rails: Talk
You can still add unpersistent attributes to your model and validate them like any other attribute on schema.

You should treat these params like any other param at controller and permit them.

Add this to your model

attr_accessor :some_attribute

So then you can do MyModel.new(some_attribute: 'foo')




Reply all
Reply to author
Forward
0 new messages