ruby-on-rails-3 – SimpleForm默认输入类

我正在使用SimpleForm Bootstrap.如何使用class = span12为所有type =“text”输入添加属性

输出如下内容的东西:

<div class="controls"><input autofocus="autofocus" class="string required span12" id="user_first_name" name="user[first_name]" required="required" size="50" type="text" value=""></div>

我试过用config.wrappers玩这个

ba.use :input,:wrap_with => { :class => 'span12' }

不起作用.它添加到包装器而不是修改输入标签.有什么想法吗?

SimpleForm.setup do |config|
  config.wrappers :bootstrap,:tag => 'div',:class => 'control-group',:error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper :tag => 'div',:class => 'controls' do |ba|
      ba.use :input
      ba.use :error,:wrap_with => { :tag => 'span',:class => 'help-inline' }
      ba.use :hint,:wrap_with => { :tag => 'p',:class => 'help-block' }
    end
  end
  config.default_wrapper = :bootstrap
end

解决方法

我有一个类似的问题,经过一些研究后我发现使用包装器api不支持.

The best you can do is use the :defaults option in each form,instead of adding for every input.

https://github.com/plataformatec/simple_form/issues/754

您可以这样实现:simple_form_for(@my_instance,认值:{input_html:{class:’span12′}})

您也可以选择使用自定义formbuilder.
https://github.com/plataformatec/simple_form#custom-form-builder

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...