Whats wrong with my collection_select


#1

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.


#2

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


#3

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:infields_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:insend’
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:inrender_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:inrender_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:inrender_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:inmeasure’
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:inperform_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:inperform_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:inmeasure’
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:inperform_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:inprocess_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:inprocess’
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:indispatch’
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:inservice’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in each' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:instart’
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:ingem_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:inrequire’
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:inrequire’
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:inrequire’
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:inform_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:insend’
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:inrender_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:inrender_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:inrender_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:inmeasure’
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:inperform_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:inperform_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:inmeasure’
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:inperform_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:inprocess_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:inprocess’
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:indispatch’
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:inservice’
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
c:/ruby/lib/ruby/1.8/webrick/server.rb:173:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:92:in each' c:/ruby/lib/ruby/1.8/webrick/server.rb:92:instart’
c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:instart’
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:ingem_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:inrequire’
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:inrequire’
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:inrequire’
script/server:3

Request

Parameters: None

Show session dump


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

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


#4

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


#5

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