1

I am upgrading to rails 3.1. in my old application.html.erb, I have a line of this:

<%= stylesheet_link_tag "themes/#{session[:theme].nil? ? 'base' : 
     session[:theme]}/ui.all" %>

As you know, I want to change the style base on the session[:theme]. Thanks to This link, I made a little progress. I modified my application.css.erb to this:

/*
* *= require_self
* */
<%
    require_asset("themes/#{session[:theme].nil? ? 'base' : 
                    session[:theme]}/ui.all" )
k%>
/* rest of file omitted */

But it complains this:

undefined local variable or method `session' for #<#<Class:0x95152e4>:0x9c6c8bc>
 (in /home/rocky/work/apps/fanfan/app/assets/stylesheets/application.css.erb)

1 Answer 1

2

The application manifest is compiled at deploy time, or compiled and cached if you are serving assets live, so you have two problems.

The first is that there is no session value available, and the second is that the even if you could change this it won't work; it would be cached the first time the manifest is compiled.

You can go back to your initial solution, and make one addition to your config for it to work.

config.assets.precompile += ['themes/theme1_name/ui.all', 'themes/theme2_name/ui.all', etc]

I am assuming here that themes is in the default stylesheets location.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.