# Problem with collection\_select

**URL:** <https://www.ruby-forum.com/t/problem-with-collection-select/150379>\
**Category:** Rails\
**Created:** [October 7, 2008, 10:21pm UTC](https://www.ruby-forum.com/t/problem-with-collection-select/150379 "2008-10-07T22:21:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kojilab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8c91f0/32.png) [@kojilab](https://www.ruby-forum.com/u/kojilab)\
**Post date:** [October 7, 2008, 10:21pm UTC](https://www.ruby-forum.com/t/problem-with-collection-select/150379/1 "2008-10-07T22:21:47Z")

</div>

Hi,

I am getting  
undefined method `map’ for #UserJob:0x7f42671ae1a8  
with the code below. I’ve looked everywhere and I don’t get what I am  
doing wrong

Controller:  
@user\_jobs = UserJob.find\_by\_user\_id(current\_user.id)

View:  
\<% form\_remote\_for(@user\_project, :complete =\>  
‘editObjectDialog.close()’) do |f| %\>  
\<%= f.error\_messages %\>  
\<% if @user\_jobs %\>

\<%= f.label :user\_job %\>  
 \<%= collection\_select :user\_project :user\_job\_id, @user\_jobs, :id, :title %\>

 \<% end %\> \<% end %\>

Thanks for your help

---

<div class="post-metadata">

**Author:** ![kojilab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8c91f0/32.png) [@kojilab](https://www.ruby-forum.com/u/kojilab)\
**Post date:** [October 7, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/problem-with-collection-select/150379/2 "2008-10-07T22:24:44Z")

</div>

On Oct 7, 9:05 pm, kojilab [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I am getting  
> undefined method `map’ for #UserJob:0x7f42671ae1a8  
> with the code below. I’ve looked everywhere and I don’t get what I am  
> doing wrong
> 
> Controller:  
> @user\_jobs = UserJob.find\_by\_user\_id(current\_user.id)

This is not an array, it’s an instance of UserJob. collection\_select  
expects an array (and judging by the variable name so are you).  
Dynamic finds of the form find\_by\_xxx are analogous to  
find :first, … whereas it looks like you want find\_all\_by\_xxx which  
is like a find :all. Having said that, most people would have the  
appropriate associations in place so that they could just write  
current\_user.user\_jobs.

Fred

---

<div class="post-metadata">

**Author:** ![kojilab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8c91f0/32.png) [@kojilab](https://www.ruby-forum.com/u/kojilab)\
**Post date:** [October 8, 2008, 7:35am UTC](https://www.ruby-forum.com/t/problem-with-collection-select/150379/3 "2008-10-08T07:35:53Z")

</div>

kojilab wrote:

> Hi,
> 
> Controller:  
> @user\_jobs = UserJob.find\_by\_user\_id(current\_user.id)
> 
> ## View: ----- \<%= collection\_select :user\_project :user\_job\_id, @user\_jobs, :id, :title %\>
> 
> Thanks for your help

I usually do this:

Controller:  
@user\_jobs\_list=[]  
@user\_jobs=UserJob.find\_by\_user\_id(current\_user.id)  
for users in @user\_jobs  
@user\_jobs\_list \<\< [users.name, users.id]  
end

and then…  
\<%=collection select :user\_project :user\_job\_id, @user\_jobs\_list, :id,  
:title%\>  
Now the collection\_select gets what it wants.

Jay
