2016-10-31 4 views
0

忘れたパスワードのリンクがあるログインフォームがあります。クリックすると、メールアドレスを入力する場所のポップアップが現れます。 正しい/既存の電子メールを入力しても問題ありませんが、間違った電子メールを入力した場合、または電子メールがデータベースに存在しない場合は、 エラーメッセージは表示されません。助けてください。devise機能付きのモーダルでエラーメッセージを忘れた場合の表示方法

<%= devise_error_messages! %>を使ってみましたが、使用しませんでした。私はエラーを表示するためにjQuery/javascriptの機能をinorderで使用しなければならないと思います。しかし、どのように モデル自体に表示するには? これが私の見解です:

<div class="container"> 
    <div class="section section-signup"> 
     <%= semantic_form_for(@resource, :as => resource_name, :url => user_session_path, :remote => true, :format => :json, :html => { :id => 'mainLogin' }) do |f| %> 
     <%= f.inputs do %> 
     <%= f.input :email, :label => 'Your email address', :input_html => { :placeholder => "Email"} %> 
       <%= f.input :password, :label => 'Your password', :input_html => { :placeholder => "Password"} %> 
      <% end %> 
     <%= f.buttons do %> 
      <% if devise_mapping.rememberable? %> 
      <%= f.input :remember_me, :as => :boolean, :label => "Remember me on this computer", :required => false, :input_html => {:class => "remember-me"} %> 
      <% end %> 
     <%= f.commit_button :label => 'Sign me in', :button_html => {:class => 'login submit button', :disable_with => 'Wait...', :id => 'user_submit' }%> 
      <% end %> 
     <div class="forgot">Yikes: <a class="pass-reset-btn cboxElement" href="#pass-reset" data-toggle="modal" data-target="#myModal">I forgot my password!</a></div> 
     <% end %> 
    </div> 
</div> 

<!-- Modal --> 
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
     <h4 class="modal-title" id="myModalLabel">Password reset</h4> 
     </div> 
     <div class="modal-body"> 
     <p>Enter your email address and we'll shoot you a link for resetting your password.</p> 
     <!-- Start Fromtastic Markup --> 
     <%= semantic_form_for(resource_name, :url => password_path(resource_name), :remote => true, :format => :json, :html => { :id => 'password_reset' }) do |f| %> 
      <%= f.inputs do %> 
      <%= f.input :email, :label => 'Your email address', :input_html => { :placeholder => "Enter your email..."}%> 
      <% end %> 
      <%= f.buttons do %> 
      <%= f.commit_button :label => 'Send me that link', :button_html => {:class => 'submit button', :disable_with => 'Wait...' }%> 
      <% end %> 
      <div class="clearfix"></div> 
     <% end %> 
     <!-- End Fromtastic Markup --> 
     </div> 
    </div> 
    </div> 
</div> 
+0

<%= devise_error_messages! %>はページの更新にのみ作用します –

答えて

0
<%= f.inputs do %> 
      <%= f.input :email, :label => 'Your email address', :placeholder => "Enter your email...", :'data-validate' => '/users/checkemail'%> 
      <% end %> 

<p id="email_search" class='email_error' style="display: none;">Email not found</p> 

$(function() { 
    var msgp = document.getElementById('email_search'); 
    $('[data-validate]').blur(function() { 
     $this = $(this); 
     $.get($this.data('validate'), { 
      email: $this.val() 
     }).success(function() { 
      $this.removeClass('field_with_errors'); 
      msgp.style['display'] = 'none'; 
     }).error(function() { 
      $this.addClass('field_with_errors'); 
      msgp.style['display'] = 'block'; 
     }); 
    }); 
}); 


In users controller: 

def checkemail 
    if params[:email] == "" 
     render :nothing => true, :status => 200 
    elsif User.where('email = ?', params[:email]).count == 0 
     render :nothing => true, :status => 409 
    else 
     render :nothing => true, :status => 200 
    end 
    return 
end 
+0

答えをありがとう。私は電子メールが存在するかどうかにかかわらず、上記のコードで試しました、それはエラー側を指しています。 – user3189916

関連する問題