dynamic layout

4,dynamic layout
有时候我们需要根据不同的用户角色来使用不同的layout,比如管理员和一般用户,比如博客换肤(也可以用更高级的theme-generator)
代码

1. class ProjectsController < ApplicationController
2. layout :user_layout
3.
4. def index
5. @projects = Project.find(:all)
6. end
7.
8. protected
9.
10. def user_layout
11. if current_user.admin?
12. "admin"
13. else
14. "application"
15. end
16. end
17. end

你可能感兴趣的:(dynamic layout)