diff options
author | Andy Waite <github.aw@andywaite.com> | 2013-05-05 12:32:00 +0100 |
---|---|---|
committer | Andy Waite <github.aw@andywaite.com> | 2013-09-18 19:56:46 +0100 |
commit | e6e0579defcfcf94ef1c4c1c7659f374a5335cdb (patch) | |
tree | d2d0b091287c7bb9f1bdcb9dd76b8d1ab1e93e3f /actionview/lib/action_view/helpers | |
parent | 539180cf8edaa405928162644dc617b4c179edff (diff) | |
download | rails-e6e0579defcfcf94ef1c4c1c7659f374a5335cdb.tar.gz rails-e6e0579defcfcf94ef1c4c1c7659f374a5335cdb.tar.bz2 rails-e6e0579defcfcf94ef1c4c1c7659f374a5335cdb.zip |
Add params option for button_to
The parameters are rendered as hidden form fields within the generated
form. This is useful for when a record has multiple buttons associated
with it, each of which target the same controller method, but which
need to submit different attributes.
Diffstat (limited to 'actionview/lib/action_view/helpers')
-rw-r--r-- | actionview/lib/action_view/helpers/url_helper.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 1920a94567..d98141b445 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -213,6 +213,7 @@ module ActionView # * <tt>:form</tt> - This hash will be form attributes # * <tt>:form_class</tt> - This controls the class of the form within which the submit button will # be placed + # * <tt>:params</tt> - Hash of parameters to be rendered as hidden fields within the form. # # ==== Data attributes # @@ -287,6 +288,7 @@ module ActionView url = options.is_a?(String) ? options : url_for(options) remote = html_options.delete('remote') + params = html_options.delete('params') method = html_options.delete('method').to_s method_tag = BUTTON_TAG_METHOD_VERBS.include?(method) ? method_tag(method) : ''.html_safe @@ -310,6 +312,11 @@ module ActionView end inner_tags = method_tag.safe_concat(button).safe_concat(request_token_tag) + if params + params.each do |name, value| + inner_tags.safe_concat tag(:input, type: "hidden", name: name, value: value.to_param) + end + end content_tag('form', content_tag('div', inner_tags), form_options) end |