ruby on rails - How to include a css or javascript in an erb that is outside the layout? -


Sorry for the little noobish question, because I'm writing my first rail app.

I think of layout view, but if you are using them, then there is no way to include a specific JS or CSS file? For example, I have layout / products.html.erb , and products_edit.css for products / edit.html.erb Should, but I do not want CSS for all product views, what is the best practice to accomplish this?

If you have a generic edit.css file, I inform you that in your layout What is

  & lt;% = stylesheet_link_tag 'edit' if parameter [: verb] == 'edit'% '  

Otherwise you can use it with yield to add additional tags in the head.

layout.html.erb

  & lt; Head & gt; ... & lt;% = yield (header) if @ content_for_header% & gt; & Lt; / Head & gt;  

Products / edit.html.erb

  & lt;% content_for: header tax -%> & Lt;% = stylesheet_link_tag 'edit_product'% & gt; & Lt;% end -% & gt;  

Comments