Ruby On Rails针对同一操作的不同视图(基于用户角色)(Ruby On Rails different views for same action (Based on User's role))
我在rails控制器上有一个ruby,它将为已注销的用户显示与登录用户不同的表单。
解决这个问题的最佳方法是什么? (以下方式好吗?)
class UsersController < ApplicationController def index if logged_in && is_admin render 'admin_index' end #use default index end endI have a ruby on rails controller that will display a different form for a logged out user than a logged in user.
What is the best way to approach this? (Is the below way ok?)
class UsersController < ApplicationController def index if logged_in && is_admin render 'admin_index' end #use default index end end最满意答案
当然没关系,除了你可能会得到一个'无法渲染动作两次'类型错误(如果我管理员并登录它仍然会尝试渲染管理员操作后呈现默认值)
class UsersController < ApplicationController def index if logged_in && is_admin render 'admin_index' else render end end end可能会更好
Sure thats fine except you might get a 'cannot render action twice' type error (if im admin and logged in it still would try to render the default after rendering the admin action)
class UsersController < ApplicationController def index if logged_in && is_admin render 'admin_index' else render end end endmight be better
更多推荐
发布评论