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 w开发者_C百科hat value is being displayed?
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.
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
精彩评论