How do I add options and fields to my form generated by a builder with form_for @user in the model? (ie. without touching the HTML)
The reason I want to do that is that I am adding a pluggable module to my model, and I want it to automatically (a) add a data attribute in the HTML to provide a hook for the Javascript, and (b) add an extra field in the form.
For example adding such a module to my model:
module Dataable
def form_options
{ 'data-foo' => true }
end
def form_builder_extra_fields
hidden_field_tag :the_data
end
end
User.send :include, Dataable
would make form_for to output:
<form {...} data-foo>
<input type="hidden" name="user[the_data]" {...} />
{...}
</form>
in the view.
Of course those methods I've just made up. The question is thus two-fold; how to add (1) form options and (2) form tags dynamically in the model.
I am in the process of prying form_for right now, but I wonder if anybody knew.
I'm not sure I fully understand what you're trying to do. If all you want to do carry some info from the controller to the form, so that it's submitted later, and using the User as a passenger.
Controller
View
If you're repeating it over and over again, and want it in the model
Model
Controller