我有以下迁移:
create_table :flows do |t|
t.string :name
t.belongs_to :subject, index: true
t.timestamps
end
我的架构:
create_table "flows", force: :cascade do |t|
t.string "name"
t.integer "subject_id"
t.index ["subject_id"], name: "index_flows_on_subject_id"
end
create_table "subjects", force: :cascade do |t|
t.string "subject"
t.datetime "created_at", null: false
end
在我的表格中,我有选择html:
<%= f.select :subject, Subject.all.collect {|s| [ s.subject, s.id ] }, {prompt: 'Select subject'}, class:"form-control" %>
但它显示错误:主题(#30363600)预期,得到字符串(#16228440)
# POST /flows.json
def create
@flow = Flow.new(flow_params)
respond_to do |format|
if @flow.save
参数:
{"utf8"=>"✓",
"authenticity_token"=>"y3cTmsdqweqioXtsCpSlNtmTonyXev+67emGwqfgvGJK4D3Szt1FbZcxe6M7QU8cLYPEbanmkYngzyDvbFPw==",
"flow"=>{"name"=>"Create Project", "subject"=>"11"},
"button"=>""}
答案 0 :(得分:0)
您有一个名为subject_id
的列,请尝试以下操作:
<%= f.select :subject_id, Subject.all.collect {|s| [ s.subject, s.id ] }, {prompt: 'Select subject'}, class:"form-control" %>
Strong Param应如下所示:
def flow_params
params.require(:flow).permit(:name, :subject_id)
end