2017-01-23 82 views
0

全新安裝Devise,我可以註冊一個新用戶。但註銷後,我無法登錄並設計返回「無效的電子郵件或密碼」。Rails 5&Devise:登錄總是返回不正確的密碼

當我看着User.last我看到正確的電子郵件。 User.last.password爲零且User.last.encrypted_password返回加密的密碼。

路線:

resources :users 
devise_for :users, path: '', path_names: { sign_up: 'register', sign_in: 'login', sign_out: 'logout'} 

註冊/新:

<%= form_for(resource, as: resource_name, url: user_registration_path, :html => {:class => "col s12 form-text"}) do |f| %> 
     <div class="row"> 
     <div class="input-field col s12"> 
      <%= f.text_field :full_name, :class => "validate", :placeholder => "Robin Smith" %> 

      <%= f.label :full_name, :class => "allcaps" %> 
     </div> 
     </div> 

     <div class="row"> 
     <div class="input-field col s12"> 
      <%= f.email_field :email, :class => "validate" %> 
      <%= f.label :email, :class => "allcaps" %> 
     </div> 
     </div> 

     <div class="row"> 
     <div class="input-field col s12"> 
      <%= f.password_field :password, :class => "validate" %> 
      <%= f.label :password, :class => "allcaps" %> 
     </div> 
     </div> 

     <div class="button-container"> 
     <%= f.submit :class => "waves-effect waves-light btn-flat", :value => "Join Now" %> 
     </div> 
    <% end %> 

節/新:

<%= form_for :session, :html => {:class => "col s12 form-text"} do |f| %> 
     <div class="row"> 
     <div class="input-field col s12"> 
      <%= f.email_field :email, :class => "validate" %> 
      <%= f.label :email, :class => "allcaps" %> 
     </div> 
     </div> 

     <div class="row"> 
     <div class="input-field col s12"> 
      <%= f.password_field :password, :class => "validate" %> 
      <%= f.label :password, :class => "allcaps" %> 
     </div> 
     </div> 

     <div class="button-container"> 
     <%= f.submit :class => "waves-effect waves-light btn-flat", :value => "Login" %> 
     </div> 
    <% end %> 

我要去哪裏錯了?

+0

看起來像您修改了Devise生成的默認會話/新視圖。這是默認設置:'<%= form_for(resource,as:resource_name,url:session_path(resource_name))do | f | %>'所以確保':session'正在做它應該做的事情。 – mmichael

+0

@mmichael謝謝 - 只是交換到您的版本,它的工作原理。我錯誤地認爲我可以交換我們的資源:session –

+0

沒問題。如果您想保留此問題,請告知我,我會根據我的評論添加答案。 – mmichael

回答

1

看起來像您修改了Devise生成的默認sessions/new view

這是默認:

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

,以便確保:session是做什麼它應該。

相關問題