# Merge error in collection\_select when trying to access another model

**URL:** <https://www.ruby-forum.com/t/merge-error-in-collection-select-when-trying-to-access-another-model/172209>\
**Category:** Rails\
**Created:** [July 16, 2009, 8:24pm UTC](https://www.ruby-forum.com/t/merge-error-in-collection-select-when-trying-to-access-another-model/172209 "2009-07-16T20:24:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![melomane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/da6949/32.png) [@melomane](https://www.ruby-forum.com/u/melomane)\
**Post date:** [July 16, 2009, 8:24pm UTC](https://www.ruby-forum.com/t/merge-error-in-collection-select-when-trying-to-access-another-model/172209/1 "2009-07-16T20:24:25Z")

</div>

Hi  
I am a newbie in rails. My question may seems too simple to be  
discussed here, but the only place to get my answer from experts is  
here. I searched in this group, but didn’t find something like my  
problem, although there were some problems about merge error.  
I have two models here, links, and subjects. every link must have a  
subject. So a subject has\_many links and links belongs\_to a subject.  
This is my new.html.erb of links:

# New link

\<% form\_for(@link) do |f| %\>  
\<%= f.error\_messages %\>

\<%= f.label :url %\>  
 \<%= f.text\_field :url %\>

\<%= f.collection\_select(:subject, :id, @subjects, :id, :title ,  
{:prompt =\> “Select a subject”}) %\>

\<%= f.submit 'Create' %\>

\<% end %\>

(in links controller, I added the second line to the scaffold-  
generated controller to access the subject:  
def create  
1 @link = Link.new(params[:link])  
2 @link.subject\_id = params[:subject][:id]  
3 respond\_to do |format|  
4 if @link.save  
…  
)  
in collection\_select, user must choose subject of the link. It only  
works when I omit “f.” in f.collection\_select although it belongs to  
this form, f. Otherwise I get this error message: undefined method  
`merge’ for :title:Symbol  
I don’t know the reason.  
I removed the f. to make the application work. I am not sure if this  
other problem is related to the previous one or not. Now, when I add  
validates\_presence\_of :url in my link model, in order to prevent the  
user to leave this field empty, instead of showing a flash when it is  
empty, I get this error messege:  
You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.map  
And it points to the line which I wrote collection\_select. I can’t  
realise the relation of url field to collection\_select!  
I appreciate everyone who helps me 🙂
