ruby-on-rails – 如何只允许管理员查看链接
发布时间:2020-12-17 02:52:20 所属栏目:百科 来源:网络整理
导读:我使用 Michael Hartl’s Rails 3 Tutorial制作管理员用户.我正在制作,因此我的管理员用户只能看到所有用户的Index.html.erb.那么,我如何仅允许我的管理员用户查看我的链接? 这是我的UsersController中的内容: before_filter :authenticate,:only = [:dest
我使用
Michael Hartl’s Rails 3 Tutorial制作管理员用户.我正在制作,因此我的管理员用户只能看到所有用户的Index.html.erb.那么,我如何仅允许我的管理员用户查看我的链接?
这是我的UsersController中的内容: before_filter :authenticate,:only => [:destroy,:index,:show,:edit,:update] before_filter :correct_user,:only => [:edit,:update] before_filter :admin_user,:only => [:index,:destroy] . . . . private . . . def admin_user authenticate redirect_to(root_path) unless current_user.admin? end 这是我正在尝试编辑管理员只看到: <% if signed_in? %> <%= link_to "Users",users_path %> <% end %> 解决方法
为此编写一个帮助方法,以便您的视图清晰可读.
your_view.html.erb <% link_to "Users",users_path if admin? %> 助手/ application_helper.rb def admin? @current_user.name == "Mr.Wallinzi" # I made up the line above. Implement your own checks according to your setup end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |