Ruby On Rails针对同一操作的不同视图(基于用户角色)(Ruby On Rails different views for same action (Based on User's

编程入门 行业动态 更新时间:2024-10-22 23:46:09
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 end

I 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 end

might be better

更多推荐

本文发布于:2023-08-07 20:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   角色   操作   用户   Ruby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!