Permalink
Browse files

Make JavaScriptHelper#j() an alias for JavaScriptHelper#escape_javasc…

…ript() -- note this then supersedes the Object#j() method that the JSON gem adds within templates using the JavaScriptHelper [DHH]
  • Loading branch information...
1 parent 45c233e commit cb3e96a447df592947ae10221c7494eb8bf08012 @dhh dhh committed Mar 26, 2011
Showing with 7 additions and 0 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +5 −0 actionpack/lib/action_view/helpers/javascript_helper.rb
View
@@ -1,5 +1,7 @@
*Rails 3.1.0 (unreleased)*
+* 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]
+
* Sensitive query string parameters (specified in config.filter_parameters) will now be filtered out from the request paths in the log file. [Prem Sichanugrist, fxn]
* URL parameters which return false for to_param now appear in the query string (previously they were removed) [Andrew White]
@@ -47,6 +47,9 @@ module JavaScriptHelper
"'" => "\\'" }
# 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 @@ def escape_javascript(javascript)
end
end
+ alias_method :escape_javascript, :j
+
# Returns a JavaScript tag with the +content+ inside. Example:
# javascript_tag "alert('All is good')"
#

0 comments on commit cb3e96a

Please sign in to comment.