# Problems returning collection\_select info to controller

**URL:** <https://www.ruby-forum.com/t/problems-returning-collection-select-info-to-controller/92556>\
**Category:** Rails\
**Created:** [April 20, 2007, 5:59pm UTC](https://www.ruby-forum.com/t/problems-returning-collection-select-info-to-controller/92556 "2007-04-20T17:59:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/4bbf92/32.png) [@lac](https://www.ruby-forum.com/u/lac)\
**Post date:** [April 20, 2007, 5:59pm UTC](https://www.ruby-forum.com/t/problems-returning-collection-select-info-to-controller/92556/1 "2007-04-20T17:59:29Z")

</div>

Hi,

I’ve been working with rails for a couple of months now and I’m  
beginning to understand how things work but this has got me baffled.

I want to return the user.id from a selection of a list of user  
names. I followed the example from AWD w/ Rails (page 487) on how to  
use collection\_select but the controller barfs because it wants a user  
and the id is coming back as a string.

Here are the code snippets:

FROM THE RHTML FORM:

\<% form\_for :master, :url =\> { :action =\> :create, :id =\> @master} do |  
form| %\>

Owner: \<%= @users = User.find(:all, :order =\> “last\_name”)  
form.collection\_select(:owner, @users, :id, :full\_name) %\>  
  
\<br/

> 

IN THE CONTROLLER:

def create  
begin  
@requirement = Requirement.new(params[:requirement]) \<\<\<\<FAILS  
HERE BECAUSE OWNER RECEIVES a STRING INSTEAD OF A USER OBJECT

IN THE MODELS:  
master.rb  
belongs\_to :owner, :class\_name =\> ‘User’, :foreign\_key =\>  
‘owner’  
user.rb  
has\_many :owned\_masters, :class\_name =\>  
‘Master’, :foreign\_key =\> ‘owner’

I suspect that my form is not quite right but I have already tried  
several different combinations, all with the same result that I gave  
here. The selection list in the html is being populated correctly  
with the names I want but when I return the id the controller says I’m  
returning a string and it wants a user object. How do I reconcile  
this?

Thanks for any suggestions,

lac
