Rails 关于 Devise 的使用问题

yfeng · 2012年01月06日 · 最后由 songlipeng2003 回复于 2012年04月28日 · 6410 次阅读

在注册页面,提交后报 TypeError in Devise::RegistrationsController#create nil is not a symbol

啥问题呢?

还有登陆时候,提交后没报异常,直接返回登陆页面,但是我看表里也没有记录登陆信息,用 user_signed_in? 返回 false。

routes 中的 root 设置了么?

# You can have the root of your site routed with "root" # just remember to delete public/index.html. root :to => 'index#index'

设置了啊

贴代码和完整报错信息。保证你的跳转到 root 的时候 root 中的代码没有错误。另外,很可能是路由问题。

路由代码: devise_for :users,:path => "account"

控制台信息: Started POST "/account/sign_in" for 127.0.0.1 at 2012-01-06 14:32:24 +0800 Processing by Devise::SessionsController#create as HTML Parameters: {"utf8"=>"鉁?, "authenticity_token"=>"0TMBy1+VHXuvP2xzy03cRrNZuR7hKKqm3a/uE+xZURo=", "user"=>{"email"=>"[email protected]", "password"=>"[FIL TERED]"}, "barcode"=>"1234"} [1m[36mUser Load (1.0ms)[0m [1mSELECT users.* FROM users WHERE users.email = '[email protected]' LIMIT 1[0m Completed 401 Unauthorized in 468ms Processing by Devise::SessionsController#new as HTML Parameters: {"utf8"=>"鉁?, "authenticity_token"=>"0TMBy1+VHXuvP2xzy03cRrNZuR7hKKqm3a/uE+xZURo=", "user"=>{"email"=>"[email protected]", "password"=>"[FIL TERED]"}, "barcode"=>"1234"} Rendered index/_top.html.erb (0.0ms) Rendered devise/sessions/new.html.erb within layouts/application (6.0ms) Completed 200 OK in 118ms (Views: 19.0ms | ActiveRecord: 0.0ms)

没有发现异常啊...

#4 楼 @yfeng 然后你发现的异常在哪里?一次把所有你掌握的信息发出来,不要挤牙膏。

没报错,我知道的已经贴出来了。

登陆后什么都没提示又返回登陆页面,就这样。 注册页面就报: TypeError in Devise::RegistrationsController#create nil is not a symbol

#6 楼 @yfeng 注册页面没有其他信息了吗?

@yfeng 你首页可以正常打开吗?devise 默认注册完毕后是跳转到 root。如果首页路由有问题就会出现你所说的问题,包括登录后没有反映。

看看 layout 中的代码有没有问题。

@rei 注册页面基本上就是 devise 自己的页面, @bony layouts/application中没什么代码. 访问首页是没问题的..不是不去首页,问题是根本就没登陆进去。

user model:

#encoding: utf-8 class User < ActiveRecord::Base set_table_name "users" # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable,:registerable,:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me end

基本上都是 devise 自动生成的

@yfeng试着重启下服务,git 回滚一下,我以前也遇到过这个情况,后来忘了是怎么改好的了。。

没用 git

看了下源码 def create

resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new") logger.debug "=========================" set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource) respond_with resource, :location => after_sign_in_path_for(resource) end

貌似在 resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new") 就出问题了, 后面的 debug 都不能正确输出..

哪位大神能帮忙看看啥问题啊。

如果都没有错误的话试着清一下 sessions,rake db:sessions:clear

抱着试试看想法做一次吧。 >.<

重新建立一个项目试了下 始终报“Invalid email or password." email 和密码填写正确也报这个..数据库我看也查询了,不过只查询的 email,条件中没加入密码..不知道哪里还配置错误

哈哈哈,已经解决。 1) TypeError in Devise::RegistrationsController#create nil is not a symbol

该错误在登陆或注册时候遇到,我把 users 表删除重新建解决,奇怪。

2) 之前说登陆后一直跳回原来页面 自己的问题,该表中有 password 字段,用来存放明文,后来试验 devise 把密码存在 encrypted_password 字段中,然后我在页面也没放

<%= notice %>

<%= alert %>

所以永远也不知道怎么回事..现在终于解决,谢谢各位

#18 楼 @yfeng Completed 401 Unauthorized in 468ms 这个问题找到什么原因啊了吗?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号