Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 用于输入的简单表单Rails配置类_Ruby On Rails_Ruby_Ruby On Rails 4_Simple Form - Fatal编程技术网

Ruby on rails 用于输入的简单表单Rails配置类

Ruby on rails 用于输入的简单表单Rails配置类,ruby-on-rails,ruby,ruby-on-rails-4,simple-form,Ruby On Rails,Ruby,Ruby On Rails 4,Simple Form,如何在Simpleform配置包装器中为输入添加类 我在下面试过,但似乎不起作用 config.wrappers :horizontal, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder b.use :label b.wrapper tag: 'div', class: 'col-lg-8' do |ba|

如何在Simpleform配置包装器中为输入添加类

我在下面试过,但似乎不起作用

config.wrappers :horizontal, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
    b.use :html5
    b.use :placeholder
    b.use :label
    b.wrapper tag: 'div', class: 'col-lg-8' do |ba|
      ba.use :input, my_wrapper_html: { class: 'form-control' }
      ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
      ba.use :error, wrap_with: { tag: 'span', class: 'help-inline text-danger' }
    end
  end

看起来这是为了实现bootstrap 3

试试这个

config.wrappers :horizontal, tag: 'div', class: 'form-group', error_class: 'has-error', defaults: { input_html: { class: 'default_class' } }  do |b|
b.use :html5
b.use :min_max
b.use :maxlength
b.use :placeholder
b.optional :pattern
b.optional :readonly

  b.wrapper tag: 'div', class: 'controls' do |input|
    input.use :label, class: 'horizontal'
    input.wrapper tag: 'div' do |prepend|
     prepend.use :input, class: 'horizontal'
    end
    input.use :hint,  wrap_with: { tag: 'span', class: 'help-block' }
    input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
  end
end
取自


我还必须添加到配置文件中,才能使输入正常工作。

不幸的是,我不确定是否可以在包装器中添加任何类来输入。就我而言,
b.use:input
的DSL没有这样的选项

您可以改用
input\u html
选项:

= f.input :title, input_html: { class: 'my-input-class' }
此功能已被描述

对于大多数复杂情况,您可以在
app/inputs
目录下定义自己的输入类:

class MyInput < SimpleForm::Inputs::BooleanInput
  html_options = label_html_options.dup
  html_options[:class] ||= []
  html_options[:class].push('my-input-class')
  @builder.label(label_target, html_options) {
    build_check_box_without_hidden_field + template.tag(:span).html_safe
  }
end

请具体说明几件事:你说它不起作用是什么意思?您是否使用任何CSS框架,其版本是什么?你的观点是什么?
= f.input :title, as: :my_input