Add theme support to rails app
Dorren_mii_thumb by dorren, 10/24/2007
If you want to add theme support to your rails app, easiest way is to use Matt McCray's theme_support plugin. just do "script/plugin install http://mattmccray.com/svn/rails/plugins/theme_support/" to get it.

1. The Problem

But it doesn't work out of box. when you start the server, you'll get error like:
theme_app/vendor/plugins/theme_support/lib/patches/routeset_ex.rb:27:in `create_theme_routes': 
undefined method `named_route' for #<actioncontroller::routing::routeset:0xb74da758> (NoMethodError)
        from theme_app/vendor/plugins/theme_support/lib/patches/routeset_ex.rb:13:in `draw'
        from ./script/../config/../config/routes.rb:1
        ...
Since the last update of the plugin was April 2006, and now is Oct 2007, so changes of rails internal must made the plugin incompatible. On Matt's blog, someone suggested a workaround, to change the route function calls in plugin's route patch (lib/patch/routeset_ex.rb). But I choose to take a more conservative approach, not to patch routing at all.

2. The Fix

So here are the changes I made to the plugin to make it futureproof.
  • Disable routing patch. comment out "require 'patches/routeset_ex'" line in theme_support/init.rb
  • Add theme routes into config/routes.rb
    
       map.theme_images "/themes/:theme/images/*filename", :controller=>'theme', :action=>'images'
       map.theme_stylesheets "/themes/:theme/stylesheets/*filename", :controller=>'theme', :action=>'stylesheets'
       map.theme_javascript "/themes/:theme/javascript/*filename", :controller=>'theme', :action=>'javascript'
    
       map.connect "/themes/*whatever", :controller=>'theme', :action=>'error'

Now start the server, and it shall work.

3. Usage

To create a new theme, do "script/generate theme YOUR_THEME_NAME", see plugin's readme for more usage.

4. Related pages

http://code.google.com/p/rails-multisite/
http://wiki.rubyonrails.org/rails/pages/View+Extensions if it's not down.
Views: 1635   Replies: 0   Tags: theme

comments

 
login or sign up to participate.




Money_dollar moneywill