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
?
In your application.html.erb
's head section, you can write
<% if content_for?(:head) %>
<%= yield(:head) %>
<% end %>
And in your _navheader.html.erb
, you define your css file (with respective path) like this:
<% content_for :head do %>
<link rel="stylesheet" href="/assets/navheader.css.scss">
<% end %>
Hope it helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.