I don’t understand why one method would work and the other would throw a NoMethodError if they come from the same lib file.
# 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 %>
… throws a NoMethodError for authorized?. If I comment that if block out, the page works fine (with 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
What gives?
Right, so I still don’t understand why that wasn’t working, but I have found an alternative solution.
(1) Leave authenticated_system.rb as is.
(2) Add a helper method to controllers/application.rb:
(3) Use the helper method instead of
authorized?. If anyone would like to explain why the original code wasn’t working, I’m all ears!(Thanks to this post)