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

user938363 picture user938363 · Jul 29, 2013 · Viewed 43.4k times · Source

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?

Answer

Thaha kp picture Thaha kp · Jul 29, 2013

Use name and value option.

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

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