我想学习轨道上的红宝石,写我自己的简单的应用程序(待办事项列表)。我现在想添加一个下拉菜单来选择一个用户来分配任务。collection_select和保存在轨道上的红宝石的记录
我schema.rb:现在
create_table "items", :force => true do |t|
t.text "description"
t.string "priority"
t.date "date"
t.time "time"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "done"
t.string "name"
end
create_table "users", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
,在我的形式我有一个字段:
<%= f.collection_select(:user, User.all, :id, :name) %>
它尽可能的工作作为展示我的用户不用。但是,当我尝试保存时,我当然得到:我已经建立了关系(用户有很多任务,任务有一个用户)。我错过了什么? 非常感谢您的帮助!
好吧让我试试,同时我通过使用下面的代码得到它的工作: <%= f.collection_select(:name,User.all,:name,:name)%> – alemur 2012-01-27 01:09:57
try:collection_select :item,:user_id,User.all,:id,:name)。 http://guides.rubyonrails.org/form_helpers.html – 2012-01-27 01:33:21