In this second part of the series on administration, you will learn how to lock down the site to keep the public from accessing the administration features.
<!-- episodes/index.rhtml -->
<% if admin? %>
<%= link_to 'New Episode', new_episode_path %>
<% end %>
# controllers/application.rb
helper_method :admin?
protected
def admin?
false
end
def authorize
unless admin?
flash[:error] = "unauthorized access"
redirect_to home_path
false
end
end
# episodes_controller.rb
before_filter :authorize, :except => :index
本文介绍如何通过编程方式限制公众访问网站的管理功能,包括使用 Ruby on Rails 实现的身份验证逻辑和授权过程。
238

被折叠的 条评论
为什么被折叠?



