I have this statement in application.html.erb:
<%= yield(:javascript) %>
and I have the following Javascript, which should respond to the yield:
<% content_for : javascript do %>
<script type="type/javascript">
$(function() {
call_to_function();
});
</script>
<% end %>
If I place the above block in home/index.html.erb, it works alright, but I want to somehow make it available to application.html.erb all the time, not just when I call home#index.
How can I achieve this, any pointers would be much appreciated?
Instead of using
you can directly put your java script to application.html.erb in app/views/layout to share code throw out all the pages.
There is no need to use yield when you have same contents through out. Yield is used when we have code specific to each page is different, from each page we call yield to actually replace the content of yield block.
So, replace <%= yield(:javascript) %> by
to appear in all your pages.