How do I use hidden_field in a form_for in Ruby on Rails?
Ref hidden_field or hidden_field_tag
<% form_for(:request, :url => requests_path) do |f| %>
<div class="actions">
<%= f.hidden_field :some_column %>
<%= hidden_field_tag 'selected', 'none' %>
<%= f.submit e %>
</div>
<% end %>
then in controller
params[:selected]="none"
params[:request][:some_column] = request.some_column
Note when you used
<%= f.hidden_field :some_column %>
it change to html
<input type="hidden" id="request_some_column" name="request[some_column]" value="#{@request.some_column}" />
and when you used
<%= hidden_field_tag 'selected', 'none' %>
it change to html
<input id="selected" name="selected" type="hidden" value="none"/>
You can send a custom value as a hidden input for your model like that:
<%= f.hidden_field :your_model_field_name, value: 12 %>
Where value: 12
is just a demo, but you can pass whatever value you need.