Search code examples
form-submitsimple-formsubmit-buttonruby-on-rails-4.1

Rails 4 simple_form field depending on submit button click


I have a simple_form with 2 submit button and depending on the button click, I would like to have one field :is_active to be true or false:

<%= f.button :submit, "active true", class: "regular", is_active: true %>
<%= f.button :submit, "active false", class: "regular", is_active: false %>

this is not working


Solution

  • You could try to use two submit_tag in same form check this . Using params hash to check which button was clicked.

    Please try like this:

    <%= submit_tag 'active true', :name => 'active_true' %>
    <%= submit_tag 'active false', :name => 'active_false' %>
    

    In controller

    if params[:active_true] 
       # do your stuff
    elsif params[:active_false]
       # do your stuff
    end