How to write css for each page in rails 3
I want to make different layouts for different pages in my rails application but if i am creating a different file in assets folder for a particular page then it is taking some values from different page and some from different that file. I am getting mad on this. I ve made a different layout file for that and include this
layout'home' in each controller( home for home page). Please help.
i found the answer. Actually its not a good practice unless and until you want a different a page in your web application which has totally different views from other pages. All you need to do is as follows:
Suppose i want a total different layout for console page. So here are the steps
- Create a layout
console.html.erbin layouts folder.
- Change this line
<%= stylesheet_link_tag "application", :media => "all" %>to
<%= stylesheet_link_tag "console_layout", :media => "all" %>.
- Also change the
- Go to
- Create a file
console_layout.css.scssin that folder and include any stylesheets if you want to add for that particular page. Suppose i want to include the
bootstrap_and_overrides.lessfile for this console page. Write like this
/* *= require 'bootstrap_and_overrides' *= require 'console' */
In the end remove
self_tree .from the application.css.
Doing this means you are actually creating a different layout, a different style sheet for that console page. After creating this it will never ever take values from other stylesheets. I would like to mention do this only if you need to create a page which has total different style and has nothing to do with the other page's styling.