RoR装置:sign_in始终返回无效的电子邮件/密码 [英] RoR devise: sign_in always returns invalid email/password

查看:119
本文介绍了RoR装置:sign_in始终返回无效的电子邮件/密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次登录时,都会收到错误消息msg,表明电子邮件/密码无效。



路线:

  devise_for:users 

devise_scope:users
get'/ users / sign_out'=> ‘devise / sessions#destroy’,:as => :destroy_user_session
post‘/ users / sign_in’=> ‘devise / sessions#create’,:as => :user_session
结束

资源:users

用户模型:

  devise:database_authenticatable,:confirmable,:recoverable,:rememberable,:trackable 

attr_accessor:password
attr_accessible:first_name,:last_name,:email,:password,:password_confirmation,:gender,:remember_me

视图:

 <%signed_in?(:user)%> 
Hi<%= current_user.first_name%>。 |不是你? <%= link_to'登出',destroy_user_session_path,:method => :删除%>
<%else%>
<%=链接到注册,signup_path%>或<%=链接到登录,user_session_path,:method => :create%>
<%end%>

我尝试将路线更改为:

  get'/ users / sign_in'=> ‘devise / sessions#new’,:as => :new_user_session 

并更改各自的路径,但这并没有什么改变。



我什至从以下视图中更改了代码:

  if signed_in?(:user )

至:

 如果是user_signed_in? 

并完成了所有这些操作,但没有任何效果。



我确实也要求devise处理确认,这是通过将生成的链接复制到浏览器中完成的,它使我第一次以用户身份登录。它还允许我通过电子邮件确认链接更改密码,这也使我在更改密码时登录。但是,一旦我注销并重新登录,它会告诉我电子邮件/密码再次无效。



有人可以帮助吗?



我正在使用Rails 3.0.7,设计1.4.5,水豚1.1.1,黄瓜1.0.6,mysql2 0.2.6和rake 0.8.7(如果有帮助的话)。



谢谢



编辑:



为了帮助将来的用户,实际上没有任何帮助宝石错了。它工作正常。问题出在我的数据库上。出于某种原因,它是从数据库中选择NULL电子邮件,而不是提取我尝试登录的用户的信息。我正在弄清楚如何立即解决此问题,一旦发现就将更新。

解决方案

我在全新安装的Devise上遇到了类似的问题,但是我发现如果我运行捆绑更新,然后重新启动可以正常工作的开发服务器。



起初,我没有在<$中看到数据库查询c $ c> development.log ,但是一旦我更新了 Gemfile (以确保我使用的是最新的Devise gem)并重新启动了服务器现在,我在日志文件中看到了数据库查询,它可以正常工作。



希望有帮助。



顺便说一句,不确定这是否对您有帮助...但这是我的 Routes.rb



<$ p中的路线$ p> devise_for:users,:path_names => {:sign_up => register,
:sign_in => 登录,
:sign_out => 登出,
:设置=>

devise_scope:user do
获得 login,:to => devise / sessions#new
获得 register,:to => devise / registrations#new
获得 settings,:to => devise / registrations#edit
获得登出,:to => devise / sessions#destroy

end


Every time I log in, I get the error msg that the email/password is invalid.

routes:

devise_for :users

devise_scope :users do
  get '/users/sign_out' => 'devise/sessions#destroy', :as => :destroy_user_session
  post '/users/sign_in' => 'devise/sessions#create', :as => :user_session
end

resources :users

user model:

devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable

attr_accessor :password
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :gender, :remember_me

view:

<% if signed_in?(:user) %>
   Hi <%= current_user.first_name %>. | Not you? <%= link_to 'Sign out', destroy_user_session_path, :method => :delete %>
<% else %>
   <%= link_to 'Sign up', signup_path %> or <%= link_to 'Sign in', user_session_path, :method => :create %>
<% end %>

I tried changing the routes to:

get '/users/sign_in' => 'devise/sessions#new', :as => :new_user_session

and changing the respective paths, but that didn't change anything.

I even changed the code in the view from:

if signed_in?(:user)

to:

if user_signed_in?

and did a combination of these things and nothing is working.

I did ask devise to handle the confirmation as well, which I did by copying the generated link to the browser and it signs me in as the user the first time. It also allows me to change the password via the email confirmation link, which also signs me in upon changing the password. But once I sign out and sign back in, it tells me that the email/password is invalid again.

Can anyone help?

I am using rails 3.0.7, devise 1.4.5, capybara 1.1.1, cucumber 1.0.6, mysql2 0.2.6 and rake 0.8.7 if that helps anyone.

Thanks

EDIT:

To help future users, there is actually nothing wrong with the gem. It works fine. The issue is with my database. For some reason, it is selecting a NULL email from the database instead of pulling the info of the user I am trying to log in. I am figuring out how to fix this now and will update once I figure it out.

解决方案

I have been having a similar issue on a fresh install of Devise, but what I found is that if I ran bundle update then restarted my dev server it works.

At first I wasn't seeing the DB query in the development.log, but once I updated my Gemfile (to make sure I am using the latest Devise gem) and restarted the server I now see the db queries in my logfile and it works (magically).

Hope that helps.

Btw, not sure if this will help you...but these are the routes in my Routes.rb

 devise_for :users, :path_names => { :sign_up => "register", 
                                      :sign_in => "login", 
                                      :sign_out => "logout",
                                      :settings => "settings" }

  devise_scope :user do
    get "login", :to => "devise/sessions#new"
    get "register", :to => "devise/registrations#new"
    get "settings", :to => "devise/registrations#edit"
    get "logout",   :to => "devise/sessions#destroy"

  end

这篇关于RoR装置:sign_in始终返回无效的电子邮件/密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆