Reputation: 91
I have a form for some model, inside this form I have some text_fields and hidden_fields that i need to use in the controller but that are not from the model.
this is a simplified version of it
<%= from_for @user do |f| %>
<%= f.text_field :name %>
<%= hidden_field :photo, value: 'blabla' %>
<%= text_field :type %>
<% f.submit %>
Lets say that the :photo and :type parameters are not in the model user but i need them to decide how to create the user.
they are going in the params hash, but all messed up. How do I access their value?
Thank you
Upvotes: 1
Views: 350
Reputation: 2087
hidden_field_tag "photo", "photo_value"
=> <input id="photo" name="photo" type="hidden" value="photo_value" />
Then in your controller:
@hidden_photo = params[:photo]
Whenever you are working with a form and want a value not associated with a model or object, then use the helpers ending in "*_tag"
Upvotes: 1