6

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?

1 Answer 1

6

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!

Sign up to request clarification or add additional context in comments.

1 Comment

@user2771150 It is dynamic way of adding contents to your <head> section from views.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.