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
- <%= link_to "Posts", posts_url %>
- Administration
- Register Now!
- <%= link_to “Logout”, logout_users_url %>
<% if superuser? %>
<% end %>
<% unless logged_in? %>
<% else %>
<% 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.
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:
9: <% end %>
Trace of template inclusion: /app/views/layouts/index.erb
RAILS_ROOT: /home/tybalt/fs/config/…
Application Trace http://localhost:3000/# | Framework
Tracehttp://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
[email protected]