Application skinning/theme support with Rails (modified from Rails Recipe)
(please excuse me for writing in English, for there's no input method installed on client's machine.)
Rails provides a lightweight, CSS-driven approach to themes.
1. Add a String field called style to your application’s controller class, say UserController.
ruby 代码
- attr_accessor = style
-
- def initialize
- @style = 'default_style'
- end
2. Modify the app/views/layouts/user.rhtml like the following
xml 代码
- <html>
- <head>
- <%= stylesheet_link_tag(@style) %>
- </head>
- <body>
- ...
- </body>
- </html>
3. You can change the theme at runtime using code like the following
ruby 代码
- def authenticate
- ...
- @style = 'user_specific_style'
- end
Then style sheet be used will change to public/stylesheets/user_specific_style.css