我是 ruby on rails 的新手,我目前正在使用 cocoon gem 在 haml 中构建一个简单的嵌套表单。下面的代码是一个显示我的“部分”数据(部分是父项)的视图,如果用户单击“添加问题”按钮,该表格将嵌入到页面中。
当表单最初呈现时,我们看到了理想的情况。部分字段在屏幕上,问题标题在其下方,“add_question”按钮也出现在那里。
当我单击“add_question”时,页面上会出现 2 个问题集 - 在部分字段上方。我希望它们出现在部分字段下方,但我不知道该怎么做。没有特殊的 CSS 影响页面,这是一个简单的页面。
剖面视图页面在这里:
%h2 Sections
= semantic_form_for @section do |f|
= f.inputs do
= f.input :title
= f.input :body, :class => "textareea", :rows => 40, :cols => 6
= f.input :image_file_name
= f.check_box :good_opinion, :class => "checkbox"
= f.label "Check me if you have a good opinion of this feature", :class => "checkbox"
%hr
%h3 Questions
#questions
= f.semantic_fields_for :section.questions do |question|
= render 'question_fields', :f => question
.links
= link_to_add_association 'add question', f, :questions
%p
%input{type: 'submit', value: 'Submit'}
question_fields 表单部分在这里(.nested-fields css 样式当前为空):
.nested-fields
= f.inputs do
= f.input :question_text
= f.input :answer_text
= f.input :section_id
= link_to_remove_association "remove question", f
知道我能做些什么来使这变得更好吗?