Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails is not passing the "commit" button parameter

Reinstalling a Rails app on a new server. Part of the app can fork in one of two directions based on the button the user selects. This part isn't working, and when I look at the log I see the values that I gave the form, execept for the commit portion of the params hash. This seems to be why the app isn't working as expected (since there's nothing in params[:commit], but I have no idea why commit would not be passed in; the request is definitely a POST request, and all of the other parameters are there.

like image 862
Wayne Molina Avatar asked Jan 04 '10 15:01

Wayne Molina


2 Answers

Just add name: "commit", value: "Save"to your form submit button:

form_for @object do |f|
  ...
  f.button :submit, "Save", name: "commit", value:"Save"
end

and then you will have params[:commit] equals to "Save" in the controller.

like image 197
okliv Avatar answered Oct 15 '22 05:10

okliv


Had a simular problem with a disable-button-on-submit feature. We solved it by adding a hidden input field with the same name and value before submitting the form.

function disableButtonAndSubmit()
{
  var input = $("<input type='hidden' />").attr("name", $(this)[0].name).attr("value", $(this)[0].value);
  $(this).closest('form').append(input);
  $(this).attr('disabled', 'disabled').html('Loading…');
  $(this).closest('form').submit();
}

$('#somewhere button').click(disableButtonAndSubmit);
like image 44
Joakim Kolsjö Avatar answered Oct 15 '22 05:10

Joakim Kolsjö