aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/url_helper.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-01-18 19:30:04 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-01-19 10:37:21 -0300
commit047097950fa82cc045a514b53354a827816dc088 (patch)
tree01163d60248f1ef4c08e8b9da37be5e7e8790b3a /actionpack/lib/action_view/helpers/url_helper.rb
parent423b2626d85f75bb5fec03909ff8963bded7c7d5 (diff)
downloadrails-047097950fa82cc045a514b53354a827816dc088.tar.gz
rails-047097950fa82cc045a514b53354a827816dc088.tar.bz2
rails-047097950fa82cc045a514b53354a827816dc088.zip
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.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index ebd1f280a8..96fc4fa414 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -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,15 @@ 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
end
end
end