Setting up html message error message in this way?

I am using Twitter-Bootstrap and want to generate the correct html to display a view of the error, as is done on the main site, which:

ex

html for the above field:

<div class="control-group error">
 <label for="inputError" class="control-label">Input with error</label>
  <div class="controls">
   <input type="text" id="inputError">
  </div>
</div>

Note: I deleted Please correct the error, <span>, I just need to enter an input field and a label.

And if I used my registration page as an example, a field email, it would be:

ex2

<div class="control-group">
 <label for="user_email" class="control-label">Email*</label>
  <div class="controls">
   <input type="email" value="" name="user[email]" id="user_email" class="span3">
  </div>
</div>

What do I need to do to make it function as before?

+5
source share
3 answers

. simple_form. :

rails generate simple_form:install --bootstrap

simple_form. .

+7

Bootstrap CSS.

:

<div class="control-group">
    <%= f.label :fieldname, t('models.model.fieldname'), :class => "control-label" %>
    <div class="controls">
        <%= f.text_field :fieldname, :class => 'input-large' %>
    </div>
</div>

f.label f.text_field, div field_with_errors ( ), HTML:

<div class="control-group">
    <div class="field_with_errors"><label class="control-label" for="model_fieldname">Field name</label></div>
    <div class="controls">
        <div class="field_with_errors"><input class="input-large" id="model_fieldname" name="model[fieldname]" size="30" type="text" value=""></div>
    </div>
</div>

, Bootstrap <div class="control-group error">, bootstrap.css. .control-group.error ... .control-group .field_with_errors .... , :

.control-group.error > label,
.control-group.error .help-block,
.control-group.error .help-inline,
.control-group .field_with_errors > label,
.control-group .field_with_errors .help-block,
.control-group .field_with_errors .help-inline {
  color: #b94a48;
}

Rails, , . , , Bootstrap, , , .

+2

Rails div field_with_errors, . div . , application.rb:

config.action_view.field_error_proc = Proc.new { |html_tag, instance| %Q(<div class="field_with_errors">#{html_tag}</div>).html_safe }

, , , Twitter Bootstrap, .

html_tag , . <input name="model[attribute]" size="30" type="text" value="">

div, ", ".

Additional information: http://guides.rubyonrails.org/configuring.html - item 3.9

+1
source

All Articles