2013-06-23 19 views
5

を私のフォームは、エラーメッセージ(名前は必須フィールドです)で次のようになります。Ruby on RailsのエラーメッセージをSimple_formに揃えるにはどうすればよいですか?現在では、

enter image description here

しかし、私は「名前」と並んで「空白にすることはできません」というエラーを入れたいです、このような:

enter image description here

私はこのコードでSimple_formクラスのブートストラップデフォルトから変更することによって、自分自身の「名前」ラベルとエラーにもっと自由を与えてくれた:

0123これらのクラスの

そして、私のCSSは次のとおりです。

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

    .cant_be_blank{ 
    font-size:12px; 
    } 

私が説明するように、私は、名前の横にエラーメッセージを揃えることができる方法上の任意のアイデア?助けてくれてありがとう。

+0

これは役立つ可能性があります:http://stackoverflow.com/questions/10911121/displaying-simple-form-error-messages-in-top-div –

答えて

5

入力ボックスの上にあるラベルにエラーが表示されました。

以下のコードでは、エラーをクラスに与えました。これは、配置などのためにフォーマットすることができますが、入力ボックスの下に空白の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クラスをフォーマットして、ラベル内のテキストのすぐ隣にテキストが表示されるようにすることができます。