开发者

How do you associate a css/sass stylesheet to a view in rails?

开发者 https://www.devze.com 2023-04-11 10:12 出处:网络
This is a really generic question, to which I haven\'t found a simple answer. I\'m dealing with messy legacy code that specifies st开发者_运维知识库yle several times for the same classes/views. I hav

This is a really generic question, to which I haven't found a simple answer.

I'm dealing with messy legacy code that specifies st开发者_运维知识库yle several times for the same classes/views. I have .sass files in app/styles, .css files in public/stylesheets and public/css

I don't understand which stylesheets includes which, or if they ever do. How do you match stylesheets to a specific view in rails? How do you define hierarchy between style so ones can override others?

What's the rails default for matching styles to views? I don't see any stylesheet_link_tag used in the app


The best way would be to put a named yield in your application layout:

<%= yield :head %>

Then use a content for block in your view:

<% content_for :head do %>
   <%= stylesheet_link_tag :my_css -%>
<% end %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号