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!

About Ashiq Alibhai

Ashiq Alibhai, PMP, has been a Rails aficionado since 2007, and developed web applications since early 2003, where he learned PHP in one summer. As the driving-force behind RailsRocket and the Launchpad project, he seeks to share the ease of development with Rails far and wide.
This entry was posted in Development and tagged , , . Bookmark the permalink.

Comments are closed.