简体   繁体   中英

Show ruby on rails server side form validation on a particular input element

What I want is that I want to show error just below every input fields. For example I have two fields name and description,then it should display error relating to name just below the name input fields and description just below the description input field.

We've recently started using client_side_validations , and it's pretty nice. You essentially just need to add :validate => true to your forms:

<%= form_for @model, :validate => true do |f| %>

You may need to add some custom JavaScript too. Check out the RailsCast for it too.

Well you can use something like this: This is what that can be used for email input field

<tr>
   <div>
    <td>   <%= u.label :email %></td>
    <td>   <%= u.text_field :email, size: 30 %> </td>
    <td>
      <% if @user.errors[:email].any? %>
        <%= @user.errors[:email].join(",") %>
      <% end %>
    </td>
   </div>
  </tr>

similarly you can use it for textarea

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM