aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/javascript_helper.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2011-03-26 10:28:39 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2011-03-26 10:28:39 -0700
commitcb3e96a447df592947ae10221c7494eb8bf08012 (patch)
treeb04bbe837b4553a70e5cdb95693b3e11b44961e9 /actionpack/lib/action_view/helpers/javascript_helper.rb
parent45c233ef819dc7b67e259dd73f24721fec28b8c8 (diff)
downloadrails-cb3e96a447df592947ae10221c7494eb8bf08012.tar.gz
rails-cb3e96a447df592947ae10221c7494eb8bf08012.tar.bz2
rails-cb3e96a447df592947ae10221c7494eb8bf08012.zip
Make JavaScriptHelper#j() an alias for JavaScriptHelper#escape_javascript() -- note this then supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper [DHH]
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascript_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index cd3a3eac80..6eda23a9a3 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -47,6 +47,9 @@ module ActionView
"'" => "\\'" }
# Escape carrier returns and single and double quotes for JavaScript segments.
+ # Also available through the alias j(). This is particularly helpful in JavaScript responses, like:
+ #
+ # $('some_element').replaceWith('<%=j render 'some/element_template' %>');
def escape_javascript(javascript)
if javascript
javascript.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] }
@@ -55,6 +58,8 @@ module ActionView
end
end
+ alias_method :escape_javascript, :j
+
# Returns a JavaScript tag with the +content+ inside. Example:
# javascript_tag "alert('All is good')"
#