Reputation: 63
I have Bootstrap gem install on my app however I want to include a special style sheet for my login page. How would I include this style sheet without making the stylesheet global for all views (This is what is happening to me.)
Upvotes: 3
Views: 1828
Reputation: 10673
1) In the controller method that renders your login page, add the following line at the end of the method:
render :layout => false
That code will prevent the application.html.erb
layout from being applied to the login page, assuming you want a 100% custom layout and stylesheet. If you're happy with the global layout being applied (the structure of the page, including any header or footer partials, etc.), then ignore this step.
2) In your login.html.erb
(or whatever file contains your view), you'll need the following line, to point at your specific css file:
<%= stylesheet_link_tag 'foo', media: 'print, screen' %>
where foo
points to a foo.css
file contained in your app/assets/stylesheets
directory. You can skip the media
bit if you don't want to differentiate between stylesheet media versions, but you may run into an issue with an unstyled view if the user ever tries to print the page, or if you're using a responsive layout.
3) Before that stylesheet link tag will work, you'll have to tell Rails to precompile it. In your_app/config/initializers/assets.rb
, add the following line:
Rails.application.config.assets.precompile += %w( foo.css )
4) Restart your Rails application.
5) Create and write your foo.css
file.
You should see your view specific css being applied. Also... I herd u liek mudkipz.
Upvotes: 2