【发布时间】:2015-08-20 10:12:49
【问题描述】:
有人可以解释一下吗? , 来自 ruby guides
<%= collection_select(:person, :city_id, City.all, :id, :name) %>
我有一个附件模型,我想在创建对象时使用组合框选择它的版本,并且我还想要一个新版本选项。
这里有什么附件
def change
create_table :attachments do |t|
t.string :filename
t.attachment :file
t.string :version
t.text :description
t.timestamps null: false
end
更新:
<%= f.collection_select( :version, Attachment.where.not(version: nil), :version, :version) %>
它是这样工作的,但我不明白,
【问题讨论】:
-
试试这个 -
<%= collection_select(:object, : attachment_id, Attachment.all, :id, :version) %> -
它说 undefined method `attachment_id',我认为对象是 :attachment ?从
-
对不起,我意识到我没有 f.collection_select,我现在处理它,但我不知道如何添加新版本选项来编写不同的东西
-
顺便说一句,我处理它,但我仍然不明白它是如何工作的
-
<%= collection_select(:f, :attachment_id, Attachment.all, :id, :version) %>我认为它可以工作,但对象的版本为空
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 select