Reputation: 57
I am using Rails's form_for
feature to create a form that builds an object. Besides the fields that provide the object's parameters, I want to include a few non-model fields that I can then access in the controller. When I use a non-model symbol for the field, f.check_box
, Rails throws an undefined method error. Can anyone explain a better way to do this?
Upvotes: 1
Views: 1794
Reputation: 5633
Yes, you would get the error because the attribute is not defined on the model.
2 ways I could think of in order to resolve this are:
Instead of binding the f.check_box
to the form, use check_box
instead, whatever name you call it will be available within the controller.
Define an attribute accessor within you model and use it with the f.check_box
.
Upvotes: 3