如何将我的错误消息与Ruby on Rails的Simple_form对齐?

CHa*_*ris 5 css ruby-on-rails simple-form twitter-bootstrap

目前,我的表单看起来像这样一个错误消息(名称是必填字段):

在此输入图像描述

但是我想把"不能为空"的错误放在"名字"旁边,如下所示:

在此输入图像描述

我通过使用以下代码更改默认引导程序Simple_form类,在"名称"标签上给自己更多自由和错误:

<%= f.input :name, :required => true, :label_html => { :class => 'edit_form_titles' }, :error_html => { :class => 'cant_be_blank'} %>
Run Code Online (Sandbox Code Playgroud)

我对这些课程的css是:

  .edit_form_titles{
  display: block;
  margin-bottom: 0px;
  color: #333333;
  }

  .cant_be_blank{
  font-size:12px;
  }
Run Code Online (Sandbox Code Playgroud)

关于我如何对齐名称旁边的错误消息的任何想法,正如我所描述的那样?谢谢你的帮助.

CHa*_*ris 5

我设法将错误显示在输入框上方的标签中.

使用下面的代码,我给了我的错误一个类,可以格式化为定位等,但在输入框下总是有一个空白的div或其他东西,它将其他输入框放在联合之外.

<%= f.input :name, :required => true, :label_html => { :class => 'edit_form_titles' }, :error_html => { :class => 'cant_be_blank'} %>
Run Code Online (Sandbox Code Playgroud)

在我的initializers/simple_form.rb中有:

  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 |input|
      input.use :input
      input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
      input.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end
Run Code Online (Sandbox Code Playgroud)

我改为:

 config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
    b.use :html5
    b.use :placeholder
    b.wrapper :tag => 'div', :class => 'label-error' do |input|
      b.use :label
      b.use :error, :wrap_with => { :tag => 'span', :class => 'help-block' }
    end
    b.wrapper :tag => 'div', :class => 'controls' do |ba|
      ba.use :input
      ba.use :hint,  :wrap_with => { :tag => 'p', :class => 'help-block' }
    end
  end
Run Code Online (Sandbox Code Playgroud)

这消除了输入框下面的空白空格,我可以格式化我的cant_be_blank类,使文本显示在我标签中的文本旁边.