# Undefined method \`fullname' for #\<User:0x357e380\>, BUT works

**URL:** <https://www.ruby-forum.com/t/undefined-method-fullname-for-user-0x357e380-but-works/79872>\
**Category:** Rails\
**Created:** [December 20, 2006, 1:36am UTC](https://www.ruby-forum.com/t/undefined-method-fullname-for-user-0x357e380-but-works/79872 "2006-12-20T01:36:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![askegg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@askegg](https://www.ruby-forum.com/u/askegg)\
**Post date:** [December 20, 2006, 1:36am UTC](https://www.ruby-forum.com/t/undefined-method-fullname-for-user-0x357e380-but-works/79872/1 "2006-12-20T01:36:40Z")

</div>

Hi all,

Please excuse the long post, but I wanted to make sure you have all the  
information…

I have a NewsModel that looks like this:

class News \< ActiveRecord::Base

belongs\_to :user

validates\_associated :user  
validates\_length\_of :title, :description, :minimum =\> 5, :allow\_nil  
=\> false

acts\_as\_commentable  
acts\_as\_taggable

def self.find\_recent  
News.find(:all, :order =\> ‘created\_at’, :limit =\> 10).reverse  
end

end

and a controller like this:  
class NewsController \< ApplicationController

def show  
begin  
@news = News.find(params[:id])  
rescue ActiveRecord::RecordNotFound  
flash[:notice] = “News item not found!”  
redirect\_to :action =\> ‘index’ and return  
else  
@comments = @news.comments  
end  
end  
end

and finally the view:  
–Show

 \<%= render :partial =\> '/news/item', :locals =\> { :item =\> @news } %\>

```
    <%= render :partial => '/comments/comment', :collection =>

```

@comments  
%\>

```
    <%= render :partial => '/comments/form' %>

```

–/comments/comment

## Comments

 \<%= comment.title -%\> 

 \<%= h comment.comment -%\> 

 \<%= comment.user.fullname -%\> \<%= time\_ago\_in\_words(comment.created\_at) -%\> ago 

* * *

As you can see, the comments partial calls comment.user.fullname, which

is defined in the UserModel:  
class User \< ActiveRecord::Base

has\_many :documents  
has\_many :events  
has\_many :news  
has\_many :comments

def fullname  
“#{firstname} #{surname}”  
end

end

When the server is first started the page renders correctly, HOWEVER if

I hit refresh it fails with:  
undefined method `fullname’ for #User:0x357e380

Extracted source (around line #10):

7: \<%= h comment.comment -%\>  
8:   
9:

  
10: \<%= comment.user.fullname -%\> \<%=  
time\_ago\_in\_words(comment.created\_at) -%\> ago  
11: 
  
12: 
* * *
  
13: 

Restarting the server fixes the issue for 1 view, then all subsequent  
views fail. Here is the console log:

Andrews-MacBook:~/Sites/tassia andrewskegg$ ./script/server  
=\> Booting Mongrel (use ‘script/server webrick’ to force WEBrick)  
=\> Rails application starting on [http://0.0.0.0:3000](http://0.0.0.0:3000)  
=\> Call with -d to detach  
=\> Ctrl-C to shutdown server  
\*\* Starting Mongrel listening at 0.0.0.0:3000  
\*\* Starting Rails with development environment…  
\*\* Rails loaded.  
\*\* Loading any Rails specific GemPlugins  
\*\* Signals ready. TERM =\> stop. USR2 =\> restart. INT =\> stop (no  
restart).  
\*\* Rails signals registered. HUP =\> reload (without restart). It  
might not work well.  
\*\* Mongrel available at 0.0.0.0:3000  
\*\* Use CTRL-C to stop.

Processing NewsController#show (for 127.0.0.1 at 2006-12-20 10:49:28)  
[GET]  
Session ID: ea9a336b5b4d1bee4d647d25de2a27e7  
Parameters: {“action”=\>“show”, “id”=\>“13”, “controller”=\>“news”}  
News Columns (0.000266) SHOW FIELDS FROM news  
News Load (0.000302) SELECT \* FROM news WHERE (news.id = 13)  
Rendering within layouts/application  
Rendering news/show  
Tagging Columns (0.000286) SHOW FIELDS FROM taggings  
Tag Load (0.000444) SELECT tags.\* FROM tags INNER JOIN taggings ON  
tags.id = taggings.tag\_id WHERE ((taggings.taggable\_type = ‘News’) AND  
(taggings.taggable\_id = 13))  
Tag Columns (0.000187) SHOW FIELDS FROM tags  
Rendered /news/\_item (0.00561)  
Comment Load (0.000301) SELECT \* FROM comments WHERE  
(comments.commentable\_id = 13 AND comments.commentable\_type = ‘News’)  
Comment Columns (0.000248) SHOW FIELDS FROM comments  
User Columns (0.000345) SHOW FIELDS FROM users  
User Load (0.000359) SELECT \* FROM users WHERE (users.id = 1)  
Rendered /comments/\_comment (0.01381)  
Rendered /comments/\_form (0.00201)  
Completed in 0.04776 (20 reqs/sec) | Rendering: 0.02942 (61%) | DB:  
0.00274 (5%) | 200 OK [[http://localhost/news/show/13](http://localhost/news/show/13)]

Processing NewsController#show (for 127.0.0.1 at 2006-12-20 10:49:32)  
[GET]  
Session ID: ea9a336b5b4d1bee4d647d25de2a27e7  
Parameters: {“action”=\>“show”, “id”=\>“13”, “controller”=\>“news”}  
News Columns (0.000273) SHOW FIELDS FROM news  
News Load (0.000314) SELECT \* FROM news WHERE (news.id = 13)  
Rendering within layouts/application  
Rendering news/show  
Tag Load (0.000489) SELECT tags.\* FROM tags INNER JOIN taggings ON  
tags.id = taggings.tag\_id WHERE ((taggings.taggable\_type = ‘News’) AND  
(taggings.taggable\_id = 13))  
Rendered /news/\_item (0.00340)  
Comment Load (0.000447) SELECT \* FROM comments WHERE  
(comments.commentable\_id = 13 AND comments.commentable\_type = ‘News’)  
User Columns (0.000271) SHOW FIELDS FROM users  
User Load (0.000356) SELECT \* FROM users WHERE (users.id = 1)

ActionView::TemplateError (undefined method `fullname’ for  
#User:0x357e380) on line #10 of app/views/comments/\_comment.rhtml:  
7: \<%= h comment.comment -%\>  
8:   
9:

  
10: \<%= comment.user.fullname -%\> \<%=  
time\_ago\_in\_words(comment.created\_at) -%\> ago  
11: 
  
12: 
* * *
  
13: 

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/base.rb:1848:in  
`method\_missing’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/associations/association\_proxy.rb:123:in  
`send’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/associations/association\_proxy.rb:123:in  
`method_missing' #{RAILS_ROOT}/app/views//comments/_comment.rhtml:10:in `\_run\_rhtml\_47app47views47comments47\_comment46rhtml’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:326:in  
`send’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:326:in  
`compile\_and\_render\_template’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:301:in  
`render\_template’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:260:in  
`render\_file’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:275:in  
`render’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/pa  
rtials.rb:59:in  
`render\_partial’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/benchmarking.rb:26:in  
`benchmark' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure’  
/usr/local/lib/ruby/1.8/benchmark.rb:307:in `realtime’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/benchmarking.rb:26:in  
`benchmark’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/pa  
rtials.rb:58:in  
`render\_partial’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/pa  
rtials.rb:73:in  
`render\_partial\_collection’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/base.rb:1361:in  
`each\_with\_index’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/associations/association\_proxy.rb:123:in  
`each’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/associations/association\_proxy.rb:123:in  
`each\_with\_index’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/associations/association\_proxy.rb:123:in  
`send’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/associations/association\_proxy.rb:123:in  
`method\_missing’

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active\_recor  
d/associations/has\_many\_association.rb:98:in  
`method\_missing’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/pa  
rtials.rb:71:in  
`render\_partial\_collection’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:285:in  
`render' #{RAILS_ROOT}/app/views/news/show.rhtml:4:in `\_run\_rhtml\_47app47views47news47show46rhtml’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:326:in  
`send’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:326:in  
`compile\_and\_render\_template’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:301:in  
`render\_template’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_view/ba  
se.rb:260:in  
`render\_file’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/base.rb:786:in  
`render\_file’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/base.rb:694:in  
`render\_with\_no\_layout’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/layout.rb:247:in  
`render\_without\_benchmark’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/benchmarking.rb:50:in  
`render' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/benchmarking.rb:50:in  
`render’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/base.rb:1069:in  
`perform\_action\_without\_filters’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/filters.rb:635:in  
`call\_filter’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/filters.rb:622:in  
`perform\_action\_without\_benchmark’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/benchmarking.rb:66:in  
`perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/benchmarking.rb:66:in  
`perform\_action\_without\_rescue’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/rescue.rb:81:in  
`perform\_action’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/base.rb:427:in  
`send’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/base.rb:427:in  
`process\_without\_filters’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/filters.rb:627:in  
`process\_without\_session\_management\_support’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/session\_management.rb:114:in  
`process’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/base.rb:330:in  
`process’

/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6.5618/lib/dispatcher.rb:41:in

`dispatch’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/rails.rb:84:  
in  
`process' /usr/local/lib/ruby/1.8/sync.rb:229:in `synchronize’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/rails.rb:83:  
in  
`process’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:580:in

`process\_client’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:579:in

`each’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:579:in

`process\_client’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:686:in

`run’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:686:in

`initialize’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:686:in

`new’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:686:in

`run’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:673:in

`initialize’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:673:in

`new’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:673:in

`run’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/configurator  
.rb:267:in  
`run’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/configurator  
.rb:266:in  
`each’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/configurator  
.rb:266:in  
`run’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel\_rails:127:in

`run’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/command.rb:2  
11:in  
`run’

/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel\_rails:231

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:482:in  
`load’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:482:in  
`load’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:337:in  
`new\_constants\_in’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:482:in  
`load’

/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6.5618/lib/commands/servers/mon  
grel.rb:52  
/usr/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:489:in  
`require’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:337:in  
`new\_constants\_in’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:489:in  
`require’

/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6.5618/lib/commands/server.rb:3  
9  
/usr/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:489:in  
`require’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:337:in  
`new\_constants\_in’

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active\_suppo  
rt/dependencies.rb:489:in  
`require’  
script/server:3

Rendering  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5618/lib/action\_control  
ler/templates/rescues/layout.rhtml  
(500 Internal Error)

Any ideas?

---

<div class="post-metadata">

**Author:** ![askegg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@askegg](https://www.ruby-forum.com/u/askegg)\
**Post date:** [December 20, 2006, 2:25am UTC](https://www.ruby-forum.com/t/undefined-method-fullname-for-user-0x357e380-but-works/79872/2 "2006-12-20T02:25:00Z")

</div>

Your user model may be getting unloaded. Are you sure your User class  
is defined in app/models/user.rb?

If the filename is different rails may to reload it properly in  
development mode.

---

<div class="post-metadata">

**Author:** ![askegg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@askegg](https://www.ruby-forum.com/u/askegg)\
**Post date:** [December 20, 2006, 5:35am UTC](https://www.ruby-forum.com/t/undefined-method-fullname-for-user-0x357e380-but-works/79872/3 "2006-12-20T05:35:06Z")

</div>

Thanks for the reply.

I have had a play around with the filenames and thought I was onto  
something, but the computer says no.  
The file is app/models/user.rb and contains:  
class User \< ActiveRecord::Base

has\_many :documents  
has\_many :events  
has\_many :news  
has\_many :comments

def fullname  
“#{firstname} #{surname}”  
end

end

I am using Rails 1.2 RC1 (ie 1.1.6) in development mode on my mac.

Interestingly, I am getting what looks like the results of “rake  
db:test” whenever I run a rake command, including “./scripts/about”. I  
wonder if this is related?

Alex W. wrote:

> Your user model may be getting unloaded. Are you sure your User class  
> is defined in app/models/user.rb?
> 
> If the filename is different rails may to reload it properly in  
> development mode.

---

<div class="post-metadata">

**Author:** ![askegg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@askegg](https://www.ruby-forum.com/u/askegg)\
**Post date:** [December 20, 2006, 10:32am UTC](https://www.ruby-forum.com/t/undefined-method-fullname-for-user-0x357e380-but-works/79872/4 "2006-12-20T10:32:31Z")

</div>

Hi Everyone,

Whatever the problem was, it has been fixed since RC1.

I just upgraded to edge rails and everything works perfectly.

---

<div class="post-metadata">

**Author:** ![askegg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@askegg](https://www.ruby-forum.com/u/askegg)\
**Post date:** [December 20, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/undefined-method-fullname-for-user-0x357e380-but-works/79872/5 "2006-12-20T22:10:13Z")

</div>

Thanks for the reply.

I have had a play around with the filenames and thought I was onto  
something, but the computer says no.  
The file is app/models/user.rb and contains:  
class User \< ActiveRecord::Base

has\_many :documents  
has\_many :events  
has\_many :news  
has\_many :comments

def fullname  
“#{firstname} #{surname}”  
end

end

I am using Rails 1.2 RC1 (ie 1.1.6) in development mode on my mac.

Interestingly, I am getting what looks like the results of “rake  
db:test” whenever I run a rake command, including “./scripts/about”. I  
wonder if this is related?

On Dec 20, 12:25 pm, Alex W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
