# Adding a css stylesheet to a plugin

**URL:** <https://www.ruby-forum.com/t/adding-a-css-stylesheet-to-a-plugin/164047>\
**Category:** Rails\
**Created:** [March 27, 2009, 8:51am UTC](https://www.ruby-forum.com/t/adding-a-css-stylesheet-to-a-plugin/164047 "2009-03-27T08:51:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nutsmuggler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/57b2e6/32.png) [@nutsmuggler](https://www.ruby-forum.com/u/nutsmuggler)\
**Post date:** [March 27, 2009, 8:51am UTC](https://www.ruby-forum.com/t/adding-a-css-stylesheet-to-a-plugin/164047/1 "2009-03-27T08:51:18Z")

</div>

Hello folks,  
I am creating a simple RoR plugin, mostly to teach myself the art of  
plugin-coding.  
The plugin is mostly a helper plugin, generating HTML code.  
Now I would like to include a CSS stylesheet ; the idea is to supply a  
“my\_plugin\_css” helper to print a link to the css stylesheet in the  
template head, but if there is a way to auto-load a css (that is,  
withoutb the plugin user intervention) I’d be happy to use it.  
Anyway, my main problem now is telling rails to load my css file as if  
it was in the usual “plublic/stylesheet” folder.  
Any suggestion?  
Davide

---

<div class="post-metadata">

**Author:** ![nutsmuggler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/57b2e6/32.png) [@nutsmuggler](https://www.ruby-forum.com/u/nutsmuggler)\
**Post date:** [March 27, 2009, 12:45pm UTC](https://www.ruby-forum.com/t/adding-a-css-stylesheet-to-a-plugin/164047/2 "2009-03-27T12:45:13Z")

</div>

I don’t think it is a good idea to try to ‘auto-load’ a css. The css  
is used in a layout, but it’s up to the user to specify which layout  
or layouts she wants to use your plugin in. Also, your css rules may  
colide with someone else’s code and if you auto-load it, it would be  
very hard to catch and debug.

I would instead use your plugin’s install.rb to move the css to public/  
stylesheets, and include instructions on how to include the CSS in  
layouts.

My $0.02.

On Mar 27, 3:51 am, Davide B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![nutsmuggler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/57b2e6/32.png) [@nutsmuggler](https://www.ruby-forum.com/u/nutsmuggler)\
**Post date:** [March 27, 2009, 4:11pm UTC](https://www.ruby-forum.com/t/adding-a-css-stylesheet-to-a-plugin/164047/3 "2009-03-27T16:11:03Z")

</div>

> I would instead use your plugin’s install.rb to move the css to public/  
> stylesheets, and include instructions on how to include the CSS in  
> layouts.

You’re definitely right here, and retrospectively it’s quite obvious,  
use install.rb and copy it.  
Thanks for your suggestion,  
Davide
