diff --git a/README.md b/README.md index 00b727f..b183027 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Creating Records of Has_One Associations](rails/creating-records-of-has-one-associations.md) - [Hash Slicing](rails/hash-slicing.md) - [Ignore Poltergeist JavaScript Errors](rails/ignore-poltergeist-javascript-errors.md) +- [Params Includes Submission Button Info](rails/params-includes-submission-button-info.md) - [Pretend Generations](rails/pretend-generations.md) - [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md) - [Select Value For SQL Counts](rails/select-value-for-sql-counts.md) diff --git a/rails/params-includes-submission-button-info.md b/rails/params-includes-submission-button-info.md new file mode 100644 index 0000000..36c7300 --- /dev/null +++ b/rails/params-includes-submission-button-info.md @@ -0,0 +1,26 @@ +# Params Includes Submission Button Info + +When a form is submitted for a Rails app, the respective controller action +will have access to a variety of information in the `params` hash. Included +is an entry with the name and value of the button that submitted the form. +By default, Rails will give the name `commit` to a submission button. + +``` +<%= f.submit %> +# results in: +Submit +``` + +The corresponding `create` action will have parameters that include that +submission button's info: + +```ruby +# in create action +> params['commit'] +=> 'Submit' +``` + +This is useful when you have multiple buttons that submit the same form, but +should have slightly different results in the corresponding action. +Differentiating becomes easy when you can easily check which was used to +submit the form. No javascript required.