I'm developing a website using Ruby on Rails. Right now, I've added a bootstrap
navigation bar in a partial file, "_navheader.html.erb"
in my layouts
folder. I render the partial right after the body
tag in application.html.erb
. The problem is that I have some CSS code for the nav bar in a separate css file. How do I link the CSS file, navheader.css.scss
to the html file, _navheader.html.erb
?
我正在开发一个使用Ruby on Rails的网站。现在,我在一个部分文件中添加了一个引导导航栏“_navheader.html”。在我的布局文件夹里。我在application.html.erb中的body标记后面呈现部分。问题是我在一个单独的CSS文件中有一些导航栏的CSS代码。如何链接CSS文件navheader.css。scss到html文件_navheader.html.erb?
1 个解决方案
#1
3
In your application.html.erb
's head section, you can write
在你application.html。erb的头部部分,你可以写
<% if content_for?(:head) %>
<%= yield(:head) %>
<% end %>
And in your _navheader.html.erb
, you define your css file (with respective path) like this:
和你的_navheader.html。erb,您定义您的css文件(有各自的路径)如下:
<% content_for :head do %>
<link rel="stylesheet" href="/assets/navheader.css.scss">
<% end %>
Hope it helps!
希望它可以帮助!
#1
3
In your application.html.erb
's head section, you can write
在你application.html。erb的头部部分,你可以写
<% if content_for?(:head) %>
<%= yield(:head) %>
<% end %>
And in your _navheader.html.erb
, you define your css file (with respective path) like this:
和你的_navheader.html。erb,您定义您的css文件(有各自的路径)如下:
<% content_for :head do %>
<link rel="stylesheet" href="/assets/navheader.css.scss">
<% end %>
Hope it helps!
希望它可以帮助!