论坛首页 编程语言技术论坛

Application skinning/theme support with Rails

浏览 2680 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-05-22  

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 代码
 
  1. attr_accessor = style  
  2.   
  3. def initialize  
  4.     @style = 'default_style'  
  5. end  

2. Modify the app/views/layouts/user.rhtml like the following

xml 代码
 
  1. <html>    
  2.   <head>    
  3.     <%= stylesheet_link_tag(@style) %>  
  4.   </head>  
  5.   <body>  
  6.   ...  
  7.   </body>  
  8. </html>  

3. You can change the theme at runtime using code like the following

ruby 代码
 
  1. def authenticate  
  2.     ...  
  3.     @style = 'user_specific_style'  
  4. end  

Then style sheet be used will change to public/stylesheets/user_specific_style.css

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics