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: , ,     Posted in Development

Rate this article:
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.5 out of 5)
Loading ... Loading ...

Related Content


Leave a Reply