views:

27

answers:

2

I'm new to rails and I guess you can answer this question easily.

What I got so far is

= f.input :task, :as => :select, :collection => @tasks, :include_blank => true

where the tasks collection is defined by

Task.find(:all)

within in the controller.

This does in fact work, shows me a dropdown-list of all Tasks to select from and connects them. The problem here is, that the dropdown menu shows me values like

#<Task:0x123456789d1234>

Where do I define what value is being displayed?

+1  A: 

I believe you can use the :label_method to solve your problem...

f.input :task, :as => :select, :collection => @tasks, 
   :include_blank => true, :label_method => :title

where :title is what you want to show.

This may help a little more.

j.
thank you very mouch, the link you posted worked great.Just had to implement a "to_label" function within the model class
Infinite
A: 

You can define a to_s method in the model:

class Task < ActiveRecord::Base

  def to_s
    title # the attribute to display for the label
  end

end
zetetic