【发布时间】:2010-09-22 21:49:39
【问题描述】:
我不明白为什么一种方法会起作用,而如果它们来自同一个 lib 文件,另一种方法会抛出 NoMethodError。
# app/views/bunnies/show.html.erb
<% if logged_in? %>
<%= current_user.login %> |
<%= link_to 'Logout', logout_path %> |
<% if authorized? %>
<%= link_to 'Edit Details', edit_bunny_path(@broker) %> |
<% end %>
<%= link_to 'Back', bunnies_path %>
<% end %>
... 为 authorized? 引发 NoMethodError。如果我评论说如果被屏蔽,则页面可以正常工作(使用logged)。_in?
# lib/authenticated_system.rb
def logged_in?
!!current_user
end
def authorized?
current_user.login == "admin"
end
# app/controllers/application.rb
class ApplicationController < ActionController::Base
include AuthenticatedSystem
end
什么给了?
【问题讨论】:
-
您是否覆盖了“已授权”?在 app/controllers/application.rb 中?还是你修改了/lib/authenticated_system.rb?
-
我只根据提供的示例修改了 /lib/authenticated_system.rb。上面的行是这个插件中我放在 application.rb 中的唯一一行。
标签: ruby-on-rails authentication