SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Nov 13, 2008, 08:38 #1
- Join Date
- Nov 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Where do I save my css files when using layouts?
Hello,
I have been reading about using layouts and have created a helloworld-layout.rhtml file in my layouts directory. Works nicely.
However, I tried sticking the CSS file in the same directory and referencing it as thus:
Code:<link href="helloworld-layout.css" rel="stylesheet" type="text/css"/>
Am I doing something wrong?
-
Nov 13, 2008, 08:52 #2
- Join Date
- Nov 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think I may have answered my own question...
I started following a tutorial it took me ages to find. (won't let me link to it)
It said I should put this bit of code where I would ordinarily reference the stylesheet. e.g:
Code:<title>Library Info System</title> <%= stylesheet_link_tag "style" %> </head>
Code:<%= stylesheet_link_tag "helloworld-layout.css" %>
Huzzah... It worked!
Sorry to have wasted anybody's time, but who knows, somebody else might find this useful.
-
Nov 16, 2008, 15:10 #3
- Join Date
- Jul 2004
- Location
- Detroit
- Posts
- 57
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That is exactly what you want to do, however, you can omit the .css from the filename. It makes it look slightly cleaner
The first example in your original post would have added a stylesheet include for public/stylesheets/style.css.David K.
-
Nov 17, 2008, 11:00 #4
- Join Date
- Feb 2007
- Posts
- 270
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Just to carry the idea a bit further:
When you have stylesheets that apply specifically to pages served through a particular layout, and no other, you can use the content_for mechanism to see they are included. For example, let's say you want some special editor styles applied whenever you have an in-line editor applied to a form. Put:
Code:<%= yield :editor %>
Code:<% content_for :editor do -%> <%= stylesheet_link_tag "editor.css" %> <% end -%>
-
Nov 26, 2008, 05:22 #5
- Join Date
- Nov 2008
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for the tips. Appreciate that very much.
Also, I just wanted to note in case any complete noobs like me are searching for an answer: it's OK to put stylesheets in a subdirectory of /public/stylesheets
I have had to create a directory for my own stylesheets and one for those needed by jQuery. I tried Googling to see if that was possible before giving it up and just trying it. So long as you remember to use the path in your tag you're fine. i.e. <%= stylesheet_link_tag "selfmade/helloworld-layout.css" %>
Unless you guys know of a better method for keeping stylesheets organised?
Bookmarks