【发布时间】:2015-07-24 18:29:00
【问题描述】:
所以我使用bootstrap-sass 和simple_form gem 并使用--boostrap 运行安装程序,这意味着它在config/initializers/ 目录中生成了simple_form_bootstrap.rb。
我正在尝试使用引导程序中的 form-horizontal 类,但这需要将 input 包装为具有 col-xx-xx 类的 div。
我查看了上述初始化程序并看到了这个块:
config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
b.optional :pattern
b.optional :min_max
b.optional :readonly
b.use :label, class: 'col-sm-3 control-label'
b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
ba.use :input, class: 'form-control'
ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
看起来初始化程序已经将正确的类应用于标签并将输入标签包装在一个 div 中。然而,这种情况并非如此。初始化器有错误吗?
以下是表格供参考:
<%= simple_form_for @article, remote: true, html: {class: "form-horizontal"} do |f| %>
<ul class="errors"></ul>
<%= f.input :author%>
<%= f.input :title%>
<%= f.button :submit, class: "btn btn-primary" %>
<% end %>
这是对应的html:
<div class="form-group string optional article_author">
<label class="string optional control-label" for="article_author">...</label>
<input id="article_author" class="string optional form-control" type=".." name=".." value="..." style="..."></input>
</div>
所以看起来初始化程序中的一些东西像类表单控件一样被添加,但不是其余的。为什么?
【问题讨论】:
标签: html css ruby-on-rails twitter-bootstrap simple-form