# Strange NoMethodError exception with EDGE Rails

**URL:** <https://www.ruby-forum.com/t/strange-nomethoderror-exception-with-edge-rails/87849>\
**Category:** Rails\
**Created:** [March 6, 2007, 11:55am UTC](https://www.ruby-forum.com/t/strange-nomethoderror-exception-with-edge-rails/87849 "2007-03-06T11:55:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndrSSSSs\_Tarsoly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@AndrSSSSs\_Tarsoly](https://www.ruby-forum.com/u/AndrSSSSs_Tarsoly)\
**Post date:** [March 6, 2007, 11:55am UTC](https://www.ruby-forum.com/t/strange-nomethoderror-exception-with-edge-rails/87849/1 "2007-03-06T11:55:25Z")

</div>

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 %\>

\<% if superuser? %\>

- Administration
  
\<% end %\>

\<% unless logged\_in? %\>

- Register Now!
  
\<% else %\>  
- \<%= link\_to “Logout”, logout\_users\_url %\>
  
\<% 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:

- Administration
  
9: \<% end %\>

Trace of template inclusion: /app/views/layouts/index.erb

RAILS\_ROOT: /home/tybalt/fs/config/…  
Application Trace [http://localhost:3000/#](http://localhost:3000/#) | Framework  
Trace[http://localhost:3000/#](http://localhost:3000/#)| Full  
Trace [http://localhost:3000/#](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/#](http://localhost:3000/#)

* * *

:return\_to: /  
flash: !map:ActionController::Flash::FlashHash {}

Response

_Headers_:

{“Status”=\>“200 OK”,  
“cookie”=\>[],  
“Cache-Control”=\>“no-cache”}

–  
AndrÃ¡s Tarsoly  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![AndrSSSSs\_Tarsoly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce7236/32.png) [@AndrSSSSs\_Tarsoly](https://www.ruby-forum.com/u/AndrSSSSs_Tarsoly)\
**Post date:** [March 6, 2007, 12:23pm UTC](https://www.ruby-forum.com/t/strange-nomethoderror-exception-with-edge-rails/87849/2 "2007-03-06T12:23:29Z")

</div>

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](http://www.rubyfrance.org) ) on Rails ( [http://www.railsfrance.org](http://www.railsfrance.org)  
)
