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
ドキュメントのIDの値を選択できるドロップダウン選択をdocument_id
(モデル内で)取得したい。Entries
私はこれまでこれを手に入れましたが、それが正しい方法であるかどうかはわかりません
models/document.rb
class Document < ApplicationRecord
has_many :Entries
end
models/entry.rb
class Entry < ApplicationRecord
belongs_to :Documents
end
誰かが私を助けてくれることを本当に願っています。タイトルにあるように、私は Rails 5 を使用しています。