# Collection\_Select not showing Selected option

**URL:** <https://www.ruby-forum.com/t/collection-select-not-showing-selected-option/125852>\
**Category:** Rails\
**Created:** [January 12, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/collection-select-not-showing-selected-option/125852 "2008-01-12T20:54:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![deadSkip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@deadSkip](https://www.ruby-forum.com/u/deadSkip)\
**Post date:** [January 12, 2008, 8:54pm UTC](https://www.ruby-forum.com/t/collection-select-not-showing-selected-option/125852/1 "2008-01-12T20:54:04Z")

</div>

Hi, I’m having some problem with getting collection\_select to return  
the current value when editing a record. According to everything I’ve  
seen, there was an issue but it’s been fixed, but I can’t figure out  
why it isn’t returning the current value as a selected option. I’ve  
checked the table structures, and both the call\_driver.product\_line\_id  
and the product\_line.id are int(11).

What am I missing?

Here’s the code;

### 
 Product Line \<%= @drivers.product\_line.name %\> # Troubleshooting only \<%= collection\_select(:driver,"product\_line\_id",@productline,:id,:name) %\> ###

The controller;

### 

def driver\_edit  
@drivers = CallDriver.find(params[:id])  
@productline = ProductLine.find(:all)  
end

### 

And the debug results for CallDriver

— &id001 !ruby/object:CallDriver  
attributes:  
name: Billing (TV)  
segment\_id: “1”  
platform\_id: “1”  
updated\_at:  
product\_line\_id: “3”  
id: “2”  
sub\_product\_line\_id: “7”  
consolidation\_id: “1”  
skill\_id: “1”  
created\_at: 2008-01-10 20:04:04  
attributes\_cache: {}

Debug results for ProductLine;

- !ruby/object:ProductLine  
attributes:  
name: RHP  
updated\_at:  
id: “1”  
created\_at: 2008-01-09 20:16:56  
attributes\_cache: {}

- !ruby/object:ProductLine  
attributes:  
name: Internet  
updated\_at:  
id: “2”  
created\_at: 2008-01-09 20:16:56  
attributes\_cache: {}

- !ruby/object:ProductLine  
attributes:  
name: TV  
updated\_at:  
id: “3”  
created\_at: 2008-01-09 20:16:56  
attributes\_cache: {}

- !ruby/object:ProductLine  
attributes:  
name: Wireless  
updated\_at:  
id: “4”  
created\_at: 2008-01-09 20:16:57  
attributes\_cache: {}

---

<div class="post-metadata">

**Author:** ![deadSkip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/839c29/32.png) [@deadSkip](https://www.ruby-forum.com/u/deadSkip)\
**Post date:** [January 13, 2008, 9:10am UTC](https://www.ruby-forum.com/t/collection-select-not-showing-selected-option/125852/2 "2008-01-13T09:10:21Z")

</div>

On 12 Jan 2008, at 19:53, deadSkip wrote:

> Here’s the code;
> 
> ### 
> Product Line \<%= @drivers.product\_line.name %\> # Troubleshooting only \<%= collection\_select(:driver,"product\_line\_id",@productline,:id,:name) %\>
> 
> Your instance variables is called @drivers, so the first parameter to  
> collection\_select must match, i.e. be :drivers (although in this case  
> it looks like it would make more sense o rename the instance variable  
> to @driver
> 
> Fred
