# NoMethodError even though the method is there

**URL:** <https://www.ruby-forum.com/t/nomethoderror-even-though-the-method-is-there/128195>\
**Category:** Rails\
**Created:** [February 5, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/nomethoderror-even-though-the-method-is-there/128195 "2008-02-05T19:29:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 5, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/nomethoderror-even-though-the-method-is-there/128195/1 "2008-02-05T19:29:05Z")

</div>

Hi,

I’m sure this will be an easy one, I’m just not seeing something  
really obvious. In my app/controllers/sessions\_controller.rb file, I  
have this method:

def create  
if (log\_user\_in(params[:login], params[:password],  
params[:remember\_me]))  
user = User.find(session[:user\_id])  
if (user.is\_subscriber?) # line  
11  
flash[:notice] = “Logged in successfully”  
redirect\_to :controller =\> ‘admin’  
else  
flash[:notice] = “Logged in successfully”  
redirect\_to :controller =\> ‘order’, :action =\> ‘new’  
end  
else  
flash[:notice] = “Authentication failed.”  
render :controller =\> ‘register’, :action =\> ‘start’  
end  
end

and in my User model, I have this method:

class User \< ActiveRecord::Base  
…  
def self.is\_subscriber?  
user\_type\_id == 1  
end  
…  
end

but I’m getting this error:

NoMethodError in SessionsController#create  
undefined method `is_subscriber?' for #<User:0xb795d668> RAILS_ROOT: /usr/local/apache2/htdocs/easyrx Application Trace | Framework Trace | Full Trace /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ attribute_methods.rb:200:in`method\_missing’  
app/controllers/sessions\_controller.rb:11:in `create’

What obvious thing am I missing?

Thanks, - Dave

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 5, 2008, 8:23pm UTC](https://www.ruby-forum.com/t/nomethoderror-even-though-the-method-is-there/128195/2 "2008-02-05T20:23:35Z")

</div>

Hey Dave, I think your problem is that you have “def  
self.is\_subscriber?” instead of “def is\_subscriber?”, which makes it a  
class method instead of an instance method. Try taking out the “self.”  
part.

Liam

removed\_email\_address@domain.invalid wrote:

> Hi,
> 
> I’m sure this will be an easy one, I’m just not seeing something  
> really obvious.  
> …  
> in my User model, I have this method:
> 
> class User \< ActiveRecord::Base  
> …  
> def self.is\_subscriber?  
> user\_type\_id == 1  
> end  
> …  
> end
> 
> but I’m getting this error:
> 
> NoMethodError in SessionsController#create  
> undefined method `is_subscriber?' for #<User:0xb795d668> RAILS_ROOT: /usr/local/apache2/htdocs/easyrx Application Trace | Framework Trace | Full Trace /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ attribute_methods.rb:200:in`method\_missing’  
> app/controllers/sessions\_controller.rb:11:in `create’
> 
> What obvious thing am I missing?
> 
> Thanks, - Dave

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 6, 2008, 10:39am UTC](https://www.ruby-forum.com/t/nomethoderror-even-though-the-method-is-there/128195/3 "2008-02-06T10:39:22Z")

</div>

def … end in not with in the clas Xyz end…

On Feb 6, 2008 12:53 AM, Liam M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Hi,  
> > end  
> > attribute\_methods.rb:200:in `method\_missing’

–  
Thanks & Regards,  
Pavan A.

NOTICE : This transmission contains information that may be confidential  
and  
that may also be privileged. Unless you are the intended recipient of  
the  
message or authorized to receive it for the intended recipient, you may  
not  
copy, forward, or otherwise use it, or disclose it or its contents to  
anyone  
else. If you have received this transmission in error please notify us  
immediately and delete it from your system.
