I've got a partial _searchresults.html.erb which has to be saved in UTF-8.
Then I've got some javaxript/AJAX code to render that partial:
<% # encoding: utf-8
%>
stopLoading();
$('#searchresults').html('<%= escape_javascript( render("shared/searchresults") ) %>');
Everytime I try to access the related page I get:
ActionView::Template::Error (invalid byte sequence in UTF-8):
1: <% # encoding: utf-8
2: %>
3: stopLoading();
4: $('#searchresults').html('<%= escape_javascript( render("shared/searchresults") ) %>');
app/views/searches/index.de.js.erb:4:in `_app_views_searches_index_de_js_erb__423966875_35661432__279394272'
All of my files are encoded with UTF-8 and all relevant *.erb files have the # encoding: utf-8 magic comment.
Is there anything I can do about this?
EDIT:
I'm now trying to escape the js manually:
def my_js_escape( js )
if( js )
ret = js.force_encoding( 'utf-8' )
ret.gsub!( /\\/u, '\\\\' )
#ret.gsub!( /<\//u, '<\/' ).force_encoding( 'utf-8' )
#ret.gsub!( /"/u, '\\"' ).force_encoding( 'utf-8' )
#ret.gsub!( /'/u, "\\'" ).force_encoding( 'utf-8' )
#/(\\|<\/|\r\n|[\n\r"'])/
return ret
else
''
end
end
Ruby gives me the same error on every gsub call, even if I put .force_encoding on all the replacement strings.