0

I have a list of checkboxes within a form, which has two buttons. I'm trying to pass in separate paramaters to the buttons as described here:

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

But it's not passing in the parameters. My code is as follows:

<%= simple_form_for :pupils, url: edit_multiple_school_group_pupils_path(school, group) do |f| %>
  ...
  ...
  <%= f.button :submit, 'Change Levels', name: 'editing', value: 'levels' %>
  <%= f.button :submit, 'Move to A Class', name: 'editing', value: 'classes' %>
<% end %>

I've tried various other methods, and have seen a few posts about giving the buttons separate ids and calling params[:commit], however no commit params are sent.

Any help is greatly appareciated.

EDIT:

The HTML output of the form buttons are:

<input type="submit" name="editing" value="levels" class="btn" />
<input type="submit" name="editing" value="classes" class="btn" />

Rails console log:

Started POST "/school/2/classes/3/pupils/edit_multiple" for 127.0.0.1 at 2017-08-08 17:08:58 +0100
Processing by Schools::Admin::PupilsController#edit_multiple as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0ncVG1+MfuS13ystwdUe/vEzF30f1iHS/F0u0DDflOXKnkw8hcUhv/n2eJZuZHOA4gZxuITahMFbyTdG/B5cEQ==", "pupil_ids"=>["134", "129"], "school_id"=>"2", "group_id"=>"3"}
2
  • Can you post the log the log that appears when you click on submit? Commented Aug 8, 2017 at 16:01
  • Sure, I've updated it with the params being submitted and the html Commented Aug 8, 2017 at 16:08

1 Answer 1

1

I recently ran into this issue. I have two submit buttons within a simple_form_for. When I post the form to the controller the :commit params are missing.

My solution is to use jquery to capture the click event for the submits that writes the submit value to a hidden input. I can then use that input value to control logic in the controller.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.