ruby-on-rails-3 – #“”}>
发布时间:2020-12-17 04:16:28 所属栏目:百科 来源:网络整理
导读:我正在尝试使用auth_logic构建一个“只需点击你的名字登录”系统.我的用户模型有一个电子邮件和名称字段.要登录,我只需: UserSession.create(@user,true) 不幸的是,这不会导致创建会话.使用调试器我发现此消息: #UserSession: {:unauthorized_record="prot
我正在尝试使用auth_logic构建一个“只需点击你的名字登录”系统.我的用户模型有一个电子邮件和名称字段.要登录,我只需:
UserSession.create(@user,true) 不幸的是,这不会导致创建会话.使用调试器我发现此消息: #<UserSession: {:unauthorized_record=>"<protected>"}> 我的用户模型只有一行: acts_as_authentic 用户会话行有这个,我在某处找到了.我不知道它做了什么,我尝试过和没有: class UserSession < Authlogic::Session::Base def to_key new_record? ? nil : [ self.send(self.class.primary_key) ] end end 数据库(我也不确定是否需要user_sessions表): create_table "sessions",:force => true do |t| t.string "session_id",:null => false t.text "data" t.datetime "created_at" t.datetime "updated_at" end add_index "sessions",["session_id"],:name => "index_sessions_on_session_id" add_index "sessions",["updated_at"],:name => "index_sessions_on_updated_at" create_table "user_sessions",:force => true do |t| t.datetime "created_at" t.datetime "updated_at" end create_table "users",:force => true do |t| t.datetime "created_at" t.datetime "updated_at" t.string "persistence_token" t.string "email" t.string "name" end 我正在使用Rails 3.0.9和我的Gemfile说(我尝试了普通和Github authlogic gem): gem 'rails','3.0.9' gem 'sqlite3' gem "authlogic" #,:git => 'git://github.com/odorcicd/authlogic.git',:branch => 'rails3' Here是源代码的其余部分. 几天前我在一个类似的项目上遇到过这个问题,并且在某个时刻它“刚刚离开”.我只是不记得怎么样. 有任何想法吗?这让我疯狂…… 解决方法
可能的解决方案……看起来有两个版本的辅助方法示例浮动.我们使用了
one:
@current_user = current_user_session && current_user_session.user 然后是一些较新的教程和示例中的the newer version: @current_user = current_user_session && current_user_session.record 显然,当在会话对象上调用.user(或任何登录字段)时,它返回unauthorized_record,而.record.user返回适当的数据. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |