Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - What is the purpose of params[:commit]

I notice that every time a Rails form is sent to the server, the name of the submit button (usually the string that is displayed on the button) is included in the params hash as "commit".

For example (last entry)

{"utf8"=>"✓",
 "authenticity_token"=>"eZABpBuW7afziDMUJtc1BNEKvGyI7NlTd9+NOYqnMxs=",
 "order"=>{"name"=>"marco",
 "email"=>"[email protected]",
 "phone"=>"0839457382",
 "collection"=>"0",
 "address"=>"18 main street, paarl",
 "city"=>"paarl",
 "country"=>"South Africa",
 "zip"=>"7646",
 "instructions"=>""},
 "terms"=>"on",
 "commit"=>"Next: 3. Payment"}

What is the purpose of this?

Is it a result of me formatting my forms incorrectly?

Here is my submit button for this specific example, taken from my form_for block

<%= f.submit 'Next: 3. Payment', :class => 'right button' %>

(The classes right button are from foundation forms.

like image 607
Marco Prins Avatar asked Apr 30 '14 08:04

Marco Prins


1 Answers

Its a way to discriminate which submit button was pushed. Could be useful if you have very different actions like:

  • save a draft
  • publish
like image 166
apneadiving Avatar answered Oct 08 '22 18:10

apneadiving