[英]How can I format this ruby on rails/ haml page to make my sub-data points appear below the main data?
我刚接触红宝石,目前正在使用茧形宝石在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形式为partial(.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
我可以做些什么使它变得更好吗?
link_to_add_association
具有以下选项:
name:
链接中显示的文本; f:表单构建器的关联。关联:需要添加新实例(符号或字符串)的关联(复数)的名称。
html_options
:额外的html-options(请参阅link_to
有一些特殊选项,前三个允许控制新链接数据的放置:
data-association-insertion-traversal
:jQuery遍历方法,允许相对于链接选择节点。 最近,下一个,子级等。默认值:绝对选择
data-association-insertion-node
:data-association-insertion-node
的jQuery选择器
也许您应该这样做:
link_to_add_association 'add question', f, :questions, data: {"association-insertion-method" => "after"}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.