我正在尝试制作一个collection_select
下拉列表,其中包含来自另一个模型的字段值。我有以下2个模型:
Documents
:
class CreateDocuments < ActiveRecord::Migration[5.0]
def change
create_table :documents do |t|
t.string :etiquette_number
t.string :etiquette_type
t.boolean :important
t.string :work_text
t.integer :user_id
t.timestamps
end
end
end
Entries
:
class CreateEntries < ActiveRecord::Migration[5.0]
def change
create_table :entries do |t|
t.integer :document_id
t.integer :user_id
t.string :work
t.date :date
t.integer :time
t.timestamps
end
end
end
我想获得一个下拉选择document_id
(在Entries
模型中),我可以在其中选择文档 id 的值。
到目前为止我得到了这个,但我不确定这是否是正确的方法
models/document.rb
class Document < ApplicationRecord
has_many :Entries
end
models/entry.rb
class Entry < ApplicationRecord
belongs_to :Documents
end
我真的希望有人可以帮助我,正如您在标题中看到的那样,我正在使用 Rails 5。