我有一个部分表格,我在两个地方使用(/ exercise / new和/ notes / new)。在第二个路径中,表单在notes视图中以模式加载。表单有一个选择字段,其中填充了一个集合,这只在第二个路径中工作正常,select是空的。
exercise_controller.rb
# GET /exercise/new
def new
@exercise = Exercise.new
end
锻炼/ _form.rb
= simple_form_for @exercise do |f|
= f.input :tag_ids, collection: ActsAsTaggableOn::Tag.order(:name), label_method: :name, value_method: :id
= f.button :submit
锻炼/ new.html.slim
h1 New exercise
== render 'form'
note_controller.rb
def new
@note = Note.new
@exercise = Exercise.new
end
请注意/ new.html.slim
h1 New Note
== render 'form' /! Note form
== render 'modal_create_exercise' /! Modal which calls exercise's form partial
请注意/ _modal_create_exercise.html.slim
.modal
.modal-header
h4 New exercise
.modal-body
== render 'exercises/form'
在这两种情况下:渲染了exercise / new和notes / new form,但在第二个选项中,值虽然在两种情况下都显示ActsAsTaggableOn::Tag.order(:name)
,但值仍为空。
答案 0 :(得分:0)
不应该是您的上一个模板note/_modal_create_exercise.html.slim
包含
== render 'exercises/form'
而不是
== 'exercises/form'