secret
Last active

I'm looking for ideas to refactor the below code into something more understandable and less error prone and ugly. Some pages in the application need one off java script included to make a feature work, but it is silly to run the java script on every other page. Any ideas?

  • Download Gist
application.html.erb
HTML+ERB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
 
<body>
...
<script>
$(function() {
<%= yield(:js) %>
});
</script>
</body>
</html>
in_the_view.html.erb
HTML+ERB
1 2 3 4 5 6 7 8 9 10
<%
 
str = <<END_OF_STRING
$('.modal').modal()
END_OF_STRING
 
content_for :js do
str.html_safe
end
%>

Sorry about the tab/spacing in application.html.erb... I did not paste it in like that, but the github editor refuses to save it correctly.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.