Hi guys, I''ve encountered a strange exception which I can just not understand why is it happening (tried to trace it back to the rails source, but I''m not an expert, so it proved no results). The situation is the following: I have a simple module ported from acts_as_authenticated, modified here and there. I have 2 methods, namely logged_in? and superuser? defined as below: # module AuthenticatedSystem module AuthenticatedSystem protected # Preloads @current_user with the user model if they''re logged in. def logged_in? current_user != :false end # Return true if current_user is root (superuser) def superuser? return false unless logged_in? current_user.roles.detect { |role| role.rights.detect { |right| right.controller == "*" && right.action == "*"}} end ... end The problem occurs in the views: I can use logged_in? just fine everywhere in the views, yet when using superuser? it throws a NoMethodError exception. A sample view: # _navigation.erb <ul id="fsNav"> <li><%= link_to "Posts", posts_url %></li> <% if superuser? %> <li><a href="#" onclick="toggleAdminMode();">Administration</a></li> <% end %> <% unless logged_in? %> <li><a href="#">Register Now!</a></li> <% else %> <li><%= link_to "Logout", logout_users_url %></li> <% end %> </ul> What I can''t understand is why logged_in? working and why superuser? is not, when they defined by the same means and at the same place. Any advice would be welcome where should I look for solving this as I''m totally clueless already and just can''t read rails source well enough to debug it myself. Thanks in advance, András -- And the exception and it''s full trace. NoMethodError in Index#index Showing *app/views/shared/_navigation.erb* where line *#7* raised: undefined method `superuser?'' for #<#<Class:0x7f061a60>:0x7f061a38> Extracted source (around line *#7*): 7: <% if superuser? %> 8: <li><a href="#" onclick="toggleAdminMode();">Administration</a></li> 9: <% end %> Trace of template inclusion: /app/views/layouts/index.erb RAILS_ROOT: /home/tybalt/fs/config/.. Application Trace <http://localhost:3000/#> | Framework Trace<http://localhost:3000/#>| Full Trace <http://localhost:3000/#> #{RAILS_ROOT}/app/views/shared/_navigation.erb:7:in `_run_erb_47app47views47shared47_navigation46erb'' #{RAILS_ROOT}/app/views/layouts/index.erb:12:in `_run_erb_47app47views47layouts47index46erb'' #{RAILS_ROOT}/app/controllers/index_controller.rb:7:in `index'' /usr/bin/mongrel_rails:16:in `load'' /usr/bin/mongrel_rails:16 #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:328:in `send'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:328:in `compile_and_render_template'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:303:in `render_template'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:263:in `render_file'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:278:in `render'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/partials.rb:59:in `render_partial'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:26:in `benchmark'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:26:in `benchmark'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/partials.rb:58:in `render_partial'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:289:in `render'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:328:in `send'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:328:in `compile_and_render_template'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:303:in `render_template'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:263:in `render_file'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/layout.rb:256:in `render_without_benchmark'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:1150:in `send'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:1150:in `perform_action_without_filters'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:632:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:438:in `call'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:438:in `call'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/rescue.rb:125:in `perform_action_without_caching'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/caching.rb:625:in `perform_action'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/query_cache.rb:99:in `cache'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/caching.rb:624:in `perform_action'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:473:in `send'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:473:in `process_without_filters'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:624:in `process_without_session_management_support'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/session_management.rb:122:in `process'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:326:in `process'' #{RAILS_ROOT}/vendor/rails/railties/lib/dispatcher.rb:39:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'' /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `initialize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 #{RAILS_ROOT}/app/views/shared/_navigation.erb:7:in `_run_erb_47app47views47shared47_navigation46erb'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:328:in `send'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:328:in `compile_and_render_template'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:303:in `render_template'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:263:in `render_file'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:278:in `render'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/partials.rb:59:in `render_partial'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:26:in `benchmark'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:26:in `benchmark'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/partials.rb:58:in `render_partial'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:289:in `render'' #{RAILS_ROOT}/app/views/layouts/index.erb:12:in `_run_erb_47app47views47layouts47index46erb'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:328:in `send'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:328:in `compile_and_render_template'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:303:in `render_template'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:263:in `render_file'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/layout.rb:256:in `render_without_benchmark'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'' #{RAILS_ROOT}/app/controllers/index_controller.rb:7:in `index'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:1150:in `send'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:1150:in `perform_action_without_filters'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:632:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:438:in `call'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:638:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:438:in `call'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:637:in `call_filter'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/rescue.rb:125:in `perform_action_without_caching'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/caching.rb:625:in `perform_action'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/query_cache.rb:99:in `cache'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/caching.rb:624:in `perform_action'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:473:in `send'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:473:in `process_without_filters'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/filters.rb:624:in `process_without_session_management_support'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/session_management.rb:122:in `process'' #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:326:in `process'' #{RAILS_ROOT}/vendor/rails/railties/lib/dispatcher.rb:39:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'' /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `initialize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /usr/bin/mongrel_rails:16:in `load'' /usr/bin/mongrel_rails:16 Request *Parameters*: None Show session dump <http://localhost:3000/#> --- :return_to: / flash: !map:ActionController::Flash::FlashHash {} Response *Headers*: {"Status"=>"200 OK", "cookie"=>[], "Cache-Control"=>"no-cache"} -- András Tarsoly tarsolya-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jean-François Trân
2007-Mar-06 11:22 UTC
Re: Strange NoMethodError exception with EDGE Rails
Hi András,> I have a simple module ported from acts_as_authenticated, > modified here and there. I have 2 methods, namely logged_in? > and superuser? defined as below: > > # module AuthenticatedSystem > module AuthenticatedSystem[...]> # Return true if current_user is root (superuser) > def superuser? > return false unless logged_in? > current_user.roles.detect { |role| role.rights.detect { |right| > right.controller == "*" && right.action == "*"}} > end > ... > end[...]> What I can''t understand is why logged_in? working and why > superuser? is not, when they defined by the same means > and at the same place.If you''ve taken the code from AuthenticatedSystem, you must have this method defined : def self.included(base) base.send :helper_method, :current_user, :logged_in? end change it to : def self.included(base) base.send :helper_method, :current_user, :logged_in?, superuser? end -- Jean-François. -- Ruby ( http://www.rubyfrance.org ) on Rails ( http://www.railsfrance.org ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---