Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to pass params when clicking submit button in simple_form view in rails 3.2.12?

In simple_form view, the submit button is like this:

<%= f.button :submit, 'Save' %> 

We are trying to pass a params subaction when clicking the Save button. The params[:subaction] should have value of 'update' after clicking the button. Here is what we tried in view but it did not work:

<%= f.button :submit, 'Save', :subaction => 'update' %> 

Is there a way to pass a value in params[:subaction] when clicking the Save button?

like image 424
user938363 Avatar asked Jul 29 '13 04:07

user938363


2 Answers

Use name and value option.

   <%= f.button  :submit , name: "subaction",value: "update"%> 

In your controller you will get params[:subaction] with the value "update"

like image 61
Thaha kp Avatar answered Sep 27 '22 23:09

Thaha kp


as dax points out,

<%= hidden_field_tag(:subaction, 'update') %> <%= f.button :submit, 'Save' %> 

This will provide the string value 'update' to the routed controller action via the hidden field. It can then be retrieved by the controller with

params[:subaction] 
like image 40
emery Avatar answered Sep 27 '22 22:09

emery