# Collection select bug (?)

**URL:** <https://www.ruby-forum.com/t/collection-select-bug/154924>\
**Category:** Rails\
**Created:** [December 5, 2008, 7:23am UTC](https://www.ruby-forum.com/t/collection-select-bug/154924 "2008-12-05T07:23:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [December 5, 2008, 7:23am UTC](https://www.ruby-forum.com/t/collection-select-bug/154924/1 "2008-12-05T07:23:11Z")

</div>

Consider this code

\<%= collection\_select :cheque, :salary\_component, Components.find  
(:all), :value, :name %\>

To input the value of a salary component into a Cheque model.  
salary\_component is an attribute of the Cheque model.  
I want the user to see the name of the component in the select  
fields… such as basic, house rent, bonus, etc  
And the amounts attributed to each of these components to get into the  
salary\_component column of the cheques table… such as 3000, 200,  
etc.  
Component is a model of its own.  
No association between Cheque and Component because, if one of the  
Components are deleted, i do not want the cheques using those  
components to get affected.  
Now, this same line in the edit page, does not show the previously  
selected value in the select.  
ie. if when a particular cheque was created, the ‘basic’ component was  
selected, the amount attributed to ‘basic’ gets into the db but when  
editing this cheque, the existing value in the collection\_select is  
not ‘basic’.  
I guess its a mapping bug. Please correct me if im wrong and DO let me  
know how to fix this. Pardon the imperfect example.
