validation - Rails does not add error classes to inputs -
i have rather basic form bunch of fields. here's excerpt:
<%= form_for(@subject) |f| %> <% if @subject.errors.any? %> <div id="error_explanation"> <h2><%= t('activerecord.errors.subject.header', :model => subject.model_name.human, :count => @subject.errors.count) %></h2> <ul> <% @subject.errors.full_messages.each |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="group"> <fieldset class="left"> <div class="field"> <%= f.label "anrede" %> <%= f.radio_button :title, "herr" %> <%= f.label :title_herr, "herr", class: "radio" %> <%= f.radio_button :title, "frau" %> <%= f.label :title_frau, "frau", class: "radio" %> </div> <div class="field"> <%= f.label :name %> <%= f.text_field :firstname, class: "m", placeholder: "vorname" %> <%= f.text_field :lastname, class: "m", placeholder: "nachname" %> </div> <div class="field"> <%= f.label "stadt" %> <%= f.select :city, subject::cities, prompt: "- bitte wählen -" %> </div> the controller still scaffold:
# post /subjects # post /subjects.json def create @subject = subject.new(subject_params) respond_to |format| if @subject.save format.html { } format.json { render action: 'create', status: :created, location: @subject } else format.html { render action: 'new' } format.json { render json: @subject.errors, status: :unprocessable_entity } end end end however when submitting invalid form, show #error_explanation-div, not wrap erroneous fields div.field_with_error once did. not sure change made break.
i not sure if behaviour expect available rails, surely can check out simple_form or formtastic gem (i'd recommend former)
Comments
Post a Comment