# Undefined method \`collect' for 1:Fixnum

**URL:** <https://www.ruby-forum.com/t/undefined-method-collect-for-1-fixnum/211048>\
**Category:** Rails\
**Created:** [August 24, 2011, 1:58pm UTC](https://www.ruby-forum.com/t/undefined-method-collect-for-1-fixnum/211048 "2011-08-24T13:58:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 24, 2011, 1:58pm UTC](https://www.ruby-forum.com/t/undefined-method-collect-for-1-fixnum/211048/1 "2011-08-24T13:58:53Z")

</div>

I am trying to do the following

\<%= effort.user\_id.collect(&:full\_name) %\>

When I run my app I get the following error: undefined method  
`collect’ for 1:Fixnum

From my understanding I believe that this maybe an association error.  
I may be incorrect.

User.rb

class User \< ActiveRecord::Base  
include ActiveModel::Validations

has\_many :roles\_users  
has\_many :roles, :through =\> :roles\_users  
has\_many :projects  
has\_many :password\_histories  
has\_many :efforts

Efforts.rb

class Effort \< ActiveRecord::Base  
belongs\_to :project\_task  
belongs\_to :user  
end

Where am i going wrong?

---

<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:** [August 24, 2011, 2:02pm UTC](https://www.ruby-forum.com/t/undefined-method-collect-for-1-fixnum/211048/2 "2011-08-24T14:02:35Z")

</div>

On Aug 24, 11:17am, “[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am trying to do the following
> 
> \<%= effort.user\_id.collect(&:full\_name) %\>
> 
> When I run my app I get the following error: undefined method  
> `collect’ for 1:Fixnum

What is that supposed to do ? user\_id is an integer so calling collect  
on it doesn’t make any sense.

Fred

---

<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:** [August 24, 2011, 2:06pm UTC](https://www.ruby-forum.com/t/undefined-method-collect-for-1-fixnum/211048/3 "2011-08-24T14:06:55Z")

</div>

On 24 Aug 2011, at 11:17, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am trying to do the following
> 
> \<%= effort.user\_id.collect(&:full\_name) %\>
> 
> When I run my app I get the following error: undefined method  
> `collect’ for 1:Fixnum
> 
> From my understanding I believe that this maybe an association error.  
> I may be incorrect.

#collect is a method you find on Enumerable objects; for example,  
Arrays. It is a synonym for #map, and lets you apply a block to each  
element of the collection:

```
[1, 2, 3, 4].collect{|x| x * 2} # => [2, 4, 6, 8]

```

You can’t send #collect to an integer (which is what you’re doing here).  
It’s undefined, and doesn’t make any sense anyway.

What are you trying to do with this line of code? My guess is that  
you’re trying to get the full\_name attribute of the user that the effort  
belongs to.

If so, remember that the association gives you a method to get the full  
User object, not just the User’s ID:

```
effort.user

```

Once you have that, you can call the #full\_name method directly:

```
effort.user.full_name

```

Is that what you’re looking for?

Chris
