Javascript Tag In Header On Select Rails Pages
I need to include an external javascript file on one page of my Rails App. I usually put my script tags in the tag, but that is controlled by application.html.erb and
Solution 1:
# application.html.erb
<head>
....
<%= javascript_include_tag "application" %>
<%= yield :head %>
</head>
# your_special_view.html.erb
<% content_for :headdo %>
<%= javascript_include_tag "some_script" %>
<% end %>
Solution 2:
You can add this to your layout, in the head section:
<%= yield:javascripts %>
Then, in your view, you can do:
<%= content_for :javascriptsdo %>
<%= javascript_include_tag :some_js %>
<% end %>
Or, if you want to specify the whole path instead of a symbol:
<%= javascript_include_tag 'path/to/js/file' %>
In the above example, the path is relative to app/assets/javascripts/
Post a Comment for "Javascript Tag In Header On Select Rails Pages"