我是铁杆新手,我想你可以轻松回答这个问题。
到目前为止我得到的是
= f.input :task, :as => :select, :collection => @tasks, :include_blank => true
其中任务集合由
定义Task.find(:all)
在控制器内。
这确实有效,向我显示了一个下拉列表,列出了要从中选择并连接它们的所有任务。 这里的问题是,下拉菜单显示了像
这样的值#<Task:0x123456789d1234>
我在哪里定义显示的值?
答案 0 :(得分:4)
我相信您可以使用:label_method
来解决您的问题...
f.input :task, :as => :select, :collection => @tasks,
:include_blank => true, :label_method => :title
其中:title
是您想要展示的内容。
This
可能会有所帮助。
答案 1 :(得分:0)
您可以在模型中定义to_s
方法:
class Task < ActiveRecord::Base
def to_s
title # the attribute to display for the label
end
end