简体   繁体   中英

Error messages on devise fields

This is my code for a devise user , i have two types of users in the application .How do i display error messages besides the fields that they arise in . As you can see , i have used devise for the users.I have been using <%= f.error_notification %> for displaying the errors but devise isn't showing it . All i see is "Please review the problems below" . Still learning on devise error views , any help on the same would be much appreciated .

<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>  

   <div class="reg-gray-box fl">


                  <ul class="reg-form">
                      <li>
                          <%= f.input :email, :label => "Email Address", :placeholder => "Email", :required => false, :autofocus => true, input_html: { class: 'wh-txt-box' } %> 
                      </li>
                      <li>
                          <%= f.input :password, :label => "Password", :placeholder => "Password", :required => false, input_html: { class: 'wh-txt-box' } %> 
                      </li>                         
                      <li>
                          <%= f.button :submit, "Sign In", :class => 'big-blue-btn' %> 
                      </li>  
                     <li>
                    <%= link_to "Forgot your password?", new_password_path(resource_name), :class =>'link' %>
                   </li>                                            
                  </ul>



    </div>

 <% end %>

Insert this <%= devise_error_messages! %> <%= devise_error_messages! %> line under this one <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %> . Like this:

<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>  
  <%= devise_error_messages! %>
  ...

I would recommend prior asking the question to appeal to documentation first, specially in such well documented cases.

Try the below one it will display the error messages.

Just add before_action :authenticate_user! in your controller.

Thanks, Vinod

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