ruby - Get erb view from inside layout -
i trying name of current view being loaded layout.erb
. trying inject js file , css file layout head. building name files based on name of erb view:
<link rel="stylesheet" href="/devcss/<%= viewname%>.css"> <script src="/devjs/<%= viewname %>.js" type="text/javascript"></script>
how can layout template?
update:i not interested in knowing how inject script in specific place in layout, think content_for used for. need knok in example above how determine viewname variable
insert following application.html.erb after inside head
tag
<%= "#{yield(:scripts)}".html_safe if content_for?(:scripts) %>
and in individual erb, insert similar following
<% content_for :scripts %> <link rel="stylesheet" href="/devcss/<%= viewname%>.css"> <script src="/devjs/<%= viewname %>.js" type="text/javascript"></script> <% end %>
this allow insert page specific codes head , other tags not accessible individual erbs
Comments
Post a Comment