I am using content_for and yeild to inject javascript files into the bottom of my layout but am wondering what the best practice is for including inline javascript. Specifi
Here's a solution if you really want to keep the number of < script> tag minimal in your html and still be able to have your IDE highlight javascript. It's really useful with jquery if you want only one $(document).ready() call in your html or with facebook js api to call js when the api is loaded, etc...
layout_helper.rb :
def javascript_jquery_ready(script)
content_for(:javascript_jquery_ready) {
script .gsub(/(
any view file:
<% javascript_jquery_ready (capture do %>
<% end) %>
This solution enable me to keep my code organise and readable in my IDE since I don't need to create partial for every js code. Even if it change nothing for the end user the html result is cleaner.