Rails 3: Serving static assets from different locations depending on theme -


i'm creating simple theme system rails 3 application. theme consists of folder placed in rails.root/themes containing

  • a .yml manifest file
  • some liquid template files
  • a static assets subfolder

now controller/action render views current theme, , using static assets accordingly.

hence need way tell rails rewrite

  • http://example.com/theme1/* ----> #{rails.root}/themes/theme1/assets/*
  • http://example.com/theme2/* ----> #{rails.root}/themes/theme2/assets/*
  • ...

currently can't figure out how since avoid both using different engine every theme or copying assets files in subfolder of public.

how can solve problem?

edit: other requirements

i looking not upset rails defaults, way later take advantage of new asset pipeline feature (planned rails 3.1).

currently found this:

config.asset_path = proc { |asset_path| "assets/#{asset_path}" }  

that have met requirements, unfortunately not apply when assets pipeline enabled.

take @ themes_for_rails plugin.

the following excerpts readme shows how can change theme used based on logic require.

in controller action:

class mycontroller < applicationcontroller   def show     theme "purple"   end end 

at class level in controller:

class mycontroller < applicationcontroller   theme "purple" # actions use theme   def show     ...   end end  

or using "resolver" lambda/function:

class mycontroller < applicationcontroller   theme :theme_resolver   # ... private   def theme_resolver     current_user.theme # or else return string.    end end 

there helper functions views , mailers.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -