aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_tag_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2012-03-14 19:28:36 -0400
committerDavid Heinemeier Hansson <david@loudthinking.com>2012-03-14 19:28:57 -0400
commite884f4b6b7440ccbeec2149669f34d2a2c14d4fb (patch)
tree1e9531d78816fd125b0f823022c7ad5bf00a82a3 /actionpack/lib/action_view/helpers/form_tag_helper.rb
parenta4c120f165c5a0b7976ba72638261c3342364e38 (diff)
downloadrails-e884f4b6b7440ccbeec2149669f34d2a2c14d4fb.tar.gz
rails-e884f4b6b7440ccbeec2149669f34d2a2c14d4fb.tar.bz2
rails-e884f4b6b7440ccbeec2149669f34d2a2c14d4fb.zip
Allow you to force the authenticity_token to be rendered even on remote forms if you pass true
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_tag_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 696688a5dd..41d895c15e 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -27,7 +27,9 @@ module ActionView
# is added to simulate the verb over post.
# * <tt>:authenticity_token</tt> - Authenticity token to use in the form. Use only if you need to
# pass custom authenticity token string, or to not add authenticity_token field at all
- # (by passing <tt>false</tt>).
+ # (by passing <tt>false</tt>). If this is a remote form, the authenticity_token will by default
+ # not be included as the ajax handler will get it from the meta-tag (but you can force it to be
+ # rendered anyway in that case by passing <tt>true</tt>).
# * A list of parameters to feed to the URL the form will be posted to.
# * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
# submit behavior. By default this behavior is an ajax submit.
@@ -617,13 +619,15 @@ module ActionView
html_options["action"] = url_for(url_for_options)
html_options["accept-charset"] = "UTF-8"
- if html_options.delete("remote")
- html_options["data-remote"] = true
+ html_options["data-remote"] = true if html_options.delete("remote")
+ if html_options["data-remote"] && html_options["authenticity_token"] == true
+ # Include the default authenticity_token, which is only generated when its set to nil,
+ # but we needed the true value to override the default of no authenticity_token on data-remote.
+ html_options["authenticity_token"] = nil
+ elsif html_options["data-remote"]
# The authenticity token is taken from the meta tag in this case
html_options["authenticity_token"] = false
- else
- html_options["authenticity_token"] = html_options.delete("authenticity_token") if html_options.has_key?("authenticity_token")
end
end
end