2013-06-23 202 views
0

我在Rails项目中使用Simple_form gem,在我出现之前有人正在处理这个项目,所以我不太熟悉它。显示simple_form消息

我在哪里可以更改显示错误消息的位置?目前它们显示在输入框下方,就像这样:

enter image description here

基本上,在我的Rails项目下落它被告知,“文本框下显示错误消息?

我可以看到:

<%= f.input :name, :required => true, :label_html => { :class => 'edit_form_titles' }, :error_html => { :class => 'cant_be_blank'} %> 

但无论我做什么,该代码,但它仍然会使文本框下方的空间。我希望邮件显示在最上方,文本框下方没有空格。在我的初始化文件夹中有一个simple_form.rb文件,可能会对其进行处理,但不确定在哪里查看或要更改什么。这是simple_form 2.0.2。

回答

1

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

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

<%= f.input :name, :required => true, :label_html => { :class => 'edit_form_titles' }, :error_html => { :class => 'cant_be_blank'} %> 

在我的初始化/ 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 

我把它改为:

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 

这让输入框和我下摆脱空白空的空间可以格式化我的cant_be_blank类,以便文本紧挨着我的标签中的文本。