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]
This commit is contained in:
parent
45c233ef81
commit
cb3e96a447
@ -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')"
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user