# Whats wrong with my collection\_select

**URL:** <https://www.ruby-forum.com/t/whats-wrong-with-my-collection-select/157989>\
**Category:** Rails\
**Created:** [January 17, 2009, 12:06pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-collection-select/157989 "2009-01-17T12:06:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [January 17, 2009, 12:06pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-collection-select/157989/1 "2009-01-17T12:06:36Z")

</div>

Hi I have two tables Projects and Tasks each with their own respective  
Ms Vs and Cs

In my add task view I want to have a drop down box with Project names. I  
cant get it to work though. Ive read posts here, the api and i dotn  
really understand what the use of the first two arguments are? Are they  
used as tags for styling or is it the address of where the selected  
value is stored in params? (im using an old version of 1.2.3 while i  
complete a book but dont think this is related to this problem)

Here is the add view

\<% form\_for :task do |form| %\>

 Task Details Title: \<%= form.text\_field :title %\> Description: \<%= form.text\_field :description %\> Priority: \<%= form.text\_field :priority %\> Completed: \<%= form.check\_box :priority %\> Project \<%= form.collection\_select(:task, :project\_id, Project.find(:all), :id, :get\_title) %\> \<%= submit\_tag "Add Task!", :class =\> "submit" %\> \<% end %\>

here is my project model

class Project \< ActiveRecord::Base  
has\_many :tasks  
validates\_presence\_of :title

#returns title  
def get\_title  
self.title  
end

end

here is the task model

class Task \< ActiveRecord::Base  
belongs\_to :project  
TITLE\_WIDTH = 30  
validates\_presence\_of :title

end

can anyone spot a mistake or help me out.

---

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [January 17, 2009, 12:10pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-collection-select/157989/2 "2009-01-17T12:10:35Z")

</div>

On 17 Jan 2009, at 11:06, Adam A. wrote:

> Hi I have two tables Projects and Tasks each with their own respective  
> Ms Vs and Cs
> 
> In my add task view I want to have a drop down box with Project  
> names. I  
> cant get it to work though.

What happens/does not happen ?

Fred

---

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [January 17, 2009, 12:36pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-collection-select/157989/3 "2009-01-17T12:36:45Z")

</div>

sorry, forgot to include that part

# heres the result from the browser

NoMethodError in Task#add

Showing app/views/task/add.rhtml where line #14 raised:

undefined method `merge’ for :get\_title:Symbol

Extracted source (around line #14):

11: Completed:  
12: \<%= form.check\_box :priority %\>  
13: Project   
14: \<%= form.collection\_select(:task, :project\_id, Project.find(:all),  
:id, :get\_title) %\>  
15: \<%= submit\_tag “Add Task!”, :class =\> “submit” %\>  
16:   
17: \<% end %\>

RAILS\_ROOT: ./script/…/config/…  
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/form\_options\_helper.rb:351:in  
`collection_select' #{RAILS_ROOT}/app/views/task/add.rhtml:14:in`\_run\_rhtml\_47app47views47task47add46rhtml’  
#{RAILS\_ROOT}/app/views/task/add.rhtml:2:in  
`\_run\_rhtml\_47app47views47task47add46rhtml’

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/form\_options\_helper.rb:351:in  
`collection_select' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:151:in`fields\_for’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/form\_helper.rb:127:in  
`form_for' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in`send’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:326:in  
`compile_and_render_template' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:301:in`render\_template’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:260:in  
`render_file' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:806:in`render\_file’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:711:in  
`render_with_no_layout' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/layout.rb:247:in`render\_without\_benchmark’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:50:in  
`render' c:/ruby/lib/ruby/1.8/benchmark.rb:293:in`measure’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:50:in  
`render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1096:in`perform\_action\_without\_filters’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:632:in  
`call_filter' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in`perform\_action\_without\_benchmark’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' c:/ruby/lib/ruby/1.8/benchmark.rb:293:in`measure’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in`perform\_action’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in`process\_without\_filters’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:624:in  
`process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in`process’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:330:in  
`process' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in`dispatch’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:113:in  
`handle_dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in`service’  
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in`run’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in`start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in`start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in`start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in`start’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:63:in  
`dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/webrick.rb:59 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in`require’  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:342:in  
`new_constants_in' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in`require’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`require’  
script/server:3

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/form\_options\_helper.rb:351:in  
`collection_select' #{RAILS_ROOT}/app/views/task/add.rhtml:14:in`\_run\_rhtml\_47app47views47task47add46rhtml’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/helpers/form\_helper.rb:151:in  
`fields_for' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:127:in`form\_for’  
#{RAILS\_ROOT}/app/views/task/add.rhtml:2:in  
`_run_rhtml_47app47views47task47add46rhtml' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in`send’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:326:in  
`compile_and_render_template' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:301:in`render\_template’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_view/base.rb:260:in  
`render_file' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:806:in`render\_file’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:711:in  
`render_with_no_layout' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/layout.rb:247:in`render\_without\_benchmark’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:50:in  
`render' c:/ruby/lib/ruby/1.8/benchmark.rb:293:in`measure’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:50:in  
`render' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1096:in`perform\_action\_without\_filters’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:632:in  
`call_filter' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in`perform\_action\_without\_benchmark’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' c:/ruby/lib/ruby/1.8/benchmark.rb:293:in`measure’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in`perform\_action’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in`process\_without\_filters’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:624:in  
`process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in`process’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:330:in  
`process' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in`dispatch’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:113:in  
`handle_dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick_server.rb:79:in`service’  
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in`run’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in`start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in`start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `each' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in`start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in`start’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/webrick\_server.rb:63:in  
`dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/webrick.rb:59 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in`require’  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/dependencies.rb:342:in  
`new_constants_in' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in`require’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`require’  
script/server:3

Request

Parameters: None

Show session dump

* * *

flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}

---

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [January 17, 2009, 2:32pm UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-collection-select/157989/4 "2009-01-17T14:32:11Z")

</div>

On 17 Jan 2009, at 11:36, Adam A. wrote:

> sorry, forgot to include that part

Because you’re using form\_for, the first argument ( :task ) should be  
dropped.

Fred

---

<div class="post-metadata">

**Author:** ![scudco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/aca169/32.png) [@scudco](https://www.ruby-forum.com/u/scudco)\
**Post date:** [January 18, 2009, 4:14am UTC](https://www.ruby-forum.com/t/whats-wrong-with-my-collection-select/157989/5 "2009-01-18T04:14:31Z")

</div>

ahh thank you very much for your help on that. I dont remember seeing  
that mentioned in the api. Ill have another look.
