diff options
author | José Valim <jose.valim@gmail.com> | 2012-01-19 05:54:35 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-01-19 05:54:35 -0800 |
commit | 5caf1bd2148825404166254f676a7d4e4615cdc7 (patch) | |
tree | 2cf761a8776fa1cd726033c6a0f2cac0122e5c87 /actionpack/lib/action_view/helpers/url_helper.rb | |
parent | b5134601adebd1dbebc18be35c5e5336011a023f (diff) | |
parent | 71597f9d51887885c826a05d14680e26c86e622f (diff) | |
download | rails-5caf1bd2148825404166254f676a7d4e4615cdc7.tar.gz rails-5caf1bd2148825404166254f676a7d4e4615cdc7.tar.bz2 rails-5caf1bd2148825404166254f676a7d4e4615cdc7.zip |
Merge pull request #4532 from rafaelfranca/av-button_to-refactor
Refactor button_to helper to use token_tag method
Diffstat (limited to 'actionpack/lib/action_view/helpers/url_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/url_helper.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index ebd1f280a8..56f999f2f5 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -327,7 +327,7 @@ module ActionView method_tag = '' if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s) - method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s) + method_tag = method_tag(method) end form_method = method.to_s == 'get' ? 'get' : 'post' @@ -336,10 +336,7 @@ module ActionView remote = html_options.delete('remote') - request_token_tag = '' - if form_method == 'post' && protect_against_forgery? - request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) - end + request_token_tag = form_method == 'post' ? token_tag : '' url = options.is_a?(String) ? options : self.url_for(options) name ||= url @@ -670,6 +667,19 @@ module ActionView bool_attrs.each { |x| html_options[x] = x if html_options.delete(x) } html_options end + + def token_tag(token=nil) + if token == false || !protect_against_forgery? + '' + else + token ||= form_authenticity_token + tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => token) + end + end + + def method_tag(method) + tag('input', :type => 'hidden', :name => '_method', :value => method.to_s) + end end end end |