Forum: Ruby on Rails CSS in Views

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Michael B. (Guest)
on 2006-02-12 02:18
How can I link to a CSS file in one of my view files?
Andrew Otwell (Guest)
on 2006-02-12 02:21
(Received via mailing list)
>How can I link to a CSS file in one of my view files?

Typically you do this in your layouts:

<%= stylesheet_link_tag "filename", :media => "all" %>

More here: http://rails.rubyonrails.com/classes/ActionView/Helpers/
AssetTagHelper.html#M000397
Michael B. (Guest)
on 2006-02-12 03:27
Andrew Otwell wrote:
>>How can I link to a CSS file in one of my view files?
>
> Typically you do this in your layouts:
>
> <%= stylesheet_link_tag "filename", :media => "all" %>
>
> More here: http://rails.rubyonrails.com/classes/ActionView/Helpers/
> AssetTagHelper.html#M000397

Thanks :)
Michael B. (Guest)
on 2006-02-12 04:24
Andrew Otwell wrote:
>>How can I link to a CSS file in one of my view files?
>
> Typically you do this in your layouts:
>
> <%= stylesheet_link_tag "filename", :media => "all" %>
>
> More here: http://rails.rubyonrails.com/classes/ActionView/Helpers/
> AssetTagHelper.html#M000397

I just tried this and in the source it is looking for
/stylesheets/filename. In RadRails you cannot create folders, so I
created the folder in explorer and moved the style.css file into that
folder, but it still is not reading it. Also, I have changed filename to
style.css. Thanks :)
Tony C. (Guest)
on 2006-02-12 04:28
(Received via mailing list)
On 2/11/06, Michael B. <removed_email_address@domain.invalid> wrote:
> I just tried this and in the source it is looking for
> /stylesheets/filename. In RadRails you cannot create folders, so I

False: Right click, choose New, Other, Simple, and choose Folder.

> created the folder in explorer and moved the style.css file into that
> folder, but it still is not reading it. Also, I have changed filename to
> style.css. Thanks :)

It's looking in the "public/stylesheets/" directory in the root of
your Rails app.


Tony
Ben M. (Guest)
on 2006-02-12 08:17
(Received via mailing list)
Tony C. wrote:
>>folder, but it still is not reading it. Also, I have changed filename to
>>style.css. Thanks :)
>
>
> It's looking in the "public/stylesheets/" directory in the root of
> your Rails app.


As Tony mentions rails is looking in the "public/stylesheets/" directory
in the root of
your Rails app... and note that rails creates this, so you shouldn't
need to.

Also, it sounded like Michael might have created something in windows
explorer and be
wondering why it's not showing up in the "Rails Navigator". If so,
that's because Eclipse
(on which RadRails is based) does not monitor the underlying file system
for changes. To
get stuff you do outside of RadRails to show up, right click on your
project in the
navigator and choose "refresh" (or click on the project and hit "F5").

Hope I'm not treading the obvious... Wasn't sure if there's some
confusion here or not...

b

PS: You can also get the "new" dialog by doing "ctrl-N"... you can see a
list of keyboard
shortcuts by doing "ctrl-shift-L" (though some aren't going to work in a
Ruby context).
Mark W. (Guest)
on 2006-02-13 20:33
(Received via mailing list)
From: "Ben M." <removed_email_address@domain.invalid>

> Eclipse (on which RadRails is based) does not monitor the underlying file
> system for changes.

You can make Eclipse 3 (at least) monitor the file system via Window |
Preferences | General | Workspace | Refresh automatically.

///ark
Ken K. (Guest)
on 2006-02-13 22:05
(Received via mailing list)
I've been using Eclipse for years now, and I can't tell you how many
times
somebody points out a capability it has that I never knew about.

Thanks for that tip.  I'm so accustomed to doing a refresh I had no idea
they found a way to make it automatic.

Ken

--
Kenneth A. Kousen, Ph.D.
President
Kousen IT, Inc.
http://www.kousenit.com
removed_email_address@domain.invalid
Ben M. (Guest)
on 2006-02-14 03:08
(Received via mailing list)
Mark W. wrote:
> From: "Ben M." <removed_email_address@domain.invalid>
>
>> Eclipse (on which RadRails is based) does not monitor the underlying
>> file system for changes.
>
>
> You can make Eclipse 3 (at least) monitor the file system via Window |
> Preferences | General | Workspace | Refresh automatically.
>

HAH! Amazing... I guess there is always something new to learn about
Eclipse! And what's really funny is that I learned
it on a ruby list! Of course, the question still remains: why doesn't
Eclipse just do that out of the box?!?

Thanks very much for that.

b
Alan F. (Guest)
on 2006-02-14 15:47
Michael B. wrote:
> Andrew Otwell wrote:
>>>How can I link to a CSS file in one of my view files?
>>
>> Typically you do this in your layouts:
>>
>> <%= stylesheet_link_tag "filename", :media => "all" %>
>>
>> More here: http://rails.rubyonrails.com/classes/ActionView/Helpers/
>> AssetTagHelper.html#M000397
>
> I just tried this and in the source it is looking for
> /stylesheets/filename. In RadRails you cannot create folders, so I
> created the folder in explorer and moved the style.css file into that
> folder, but it still is not reading it. Also, I have changed filename to
> style.css. Thanks :)


If your css file is living in myrailsapp/public/stylesheets and is
called mystylesheet.css, you would use <%= stylesheet_link_tag
"mystylesheet", :media => "all" %>

The string you pass is the name of the file, minus the extension.  Since
your file is called style.css, you should use <%= stylesheet_link_tag
"style" %>.

Is this any clearer ?

A.
This topic is locked and can not be replied to.