2013-06-23 109 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類,以便文本緊挨着我的標籤中的文本。