Adding Stylesheets
In terms of usability, maintainability, and accessibility–not to mention lowering page-sizes–using stylesheets (CSS) works in your best interest.
But you know that already. So let’s dive into the details–how exactly do you add a global stylesheet to your application (as opposed to one specific to certain objects)? Rails uses the MVC design pattern–so where does the stylesheet go?
The answer is: in the /public/stylesheets folder. Simply create a new file (eg. mystyles.css) and fill it with your CSS code.
Then, on any pages where you want to link the stylesheet, add this line of code in the header tag:
<%= stylesheet_link_tag "mystyles" %>
And voila! Rails automatically picks up the file extension! Awesome!
Tags: css, introductory, mvc Posted in


(1 votes, average: 4 out of 5)
Leave a Reply