Forum: Ruby on Rails Controller-specific stylesheets and stylesheet_link_tag and

366dbda84e78aff8a8a070622aeb63ce?d=identicon&s=25 Gioele Barabucci (Guest)
on 2014-06-27 16:32
(Received via mailing list)
Hello,

I would like to use controller-specific stylesheets instead of the usual
`application.css`. So, if a page were rendered by controller Foo it
would include only the stylesheet whose source is
`app/assets/stylesheets/foo.css.scss`.

I am using Rails 4.0.x.

I tried replacing

     stylesheet_link_tag('application')

with

     stylesheet_link_tag(params[:controller])

in the default layout as suggested by the assets guide [1] but is not
producing the expected effects.

The first statement returns

     <link href="/assets/application.css?body=1" …

while the second returns

     <link href="/stylesheets/foo.css" …

How can I make my controller-specific stylesheet go through the assets
pipeline?

Bye,

[1] http://guides.rubyonrails.org/v4.0.6/asset_pipeline.html

--
Gioele Barabucci <gioele@svario.it>
768c876fae43fc20f02534cbef3f1b64?d=identicon&s=25 Carlos Mathiasen (Guest)
on 2014-06-27 16:42
(Received via mailing list)
You can use a specific css file for each controller, just called the css
file like your controller:
   app/assets/stylesheets/greetings.css.scss

Also you can use the params[:controller] in your layout to load styles
only
for a specific controller( I don't know if that is a good practice)
like:

if params[:controller] == "greeting"

end



Matt's
366dbda84e78aff8a8a070622aeb63ce?d=identicon&s=25 Gioele Barabucci (Guest)
on 2014-06-27 16:54
(Received via mailing list)
Am 27.06.2014 16:40, schrieb Carlos Mathiasen:
> You can use a specific css file for each controller, just called the css
> file like your controller:
> |   app/assets/stylesheets/greetings.css.scss|

Hi,

this is exactly what I have, yet the `stylesheet_link_tag` method does
not behave in the way I am expecting it to behave.

Bye,

> On Fri, Jun 27, 2014 at 10:30 AM, Gioele Barabucci
>> So, if a page were rendered by controller Foo it would include only
>> the stylesheet whose source is `app/assets/stylesheets/foo.css.scss`.

--
Gioele Barabucci <gioele@svario.it>
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.