Ruby on rails 无法在Rails 3.0.1上使用Authlogic设置当前用户
我让官方的authlogic插件在Rails 2.3.5上完美运行。我将应用程序转换为Rails 3.0.1,现在遇到了一些问题 我已将以下authlogic gem包含在我的gem文件中Ruby on rails 无法在Rails 3.0.1上使用Authlogic设置当前用户,ruby-on-rails,ruby-on-rails-3,authlogic,Ruby On Rails,Ruby On Rails 3,Authlogic,我让官方的authlogic插件在Rails 2.3.5上完美运行。我将应用程序转换为Rails 3.0.1,现在遇到了一些问题 我已将以下authlogic gem包含在我的gem文件中 gem'authlogic',:git=>'git://github.com/odorcicd/authlogic.git“,:branch=>“rails3” 当用户登录时,将保存会话。调用该用户会话时,返回值为nilUserSession.find返回一个nil值,因此我无法分配当前用户 会话\u con
gem'authlogic',:git=>'git://github.com/odorcicd/authlogic.git“,:branch=>“rails3”
当用户登录时,将保存会话。调用该用户会话时,返回值为nilUserSession.find返回一个nil值
,因此我无法分配当前用户
会话\u controller.rb
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save!
flash[:notice] = 'Login successful'
redirect_to root_url
else
render :action => 'new'
end
end
helper_method :current_user, :current_user_session
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
应用程序\u controller.rb
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save!
flash[:notice] = 'Login successful'
redirect_to root_url
else
render :action => 'new'
end
end
helper_method :current_user, :current_user_session
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
当用户登录时,flash通知返回“登录成功”
,但未设置当前用户。我也尝试了官方的authlogic插件,但没有任何改变。我是不是遗漏了什么
谢谢
蒂姆我确实有这个问题。出于某种原因,它干扰了基本身份验证-为了修复它,我将allow_http_basic_auth设置为false
class UserSession < Authlogic::Session::Base
allow_http_basic_auth false
end
class UserSession
哇,这真是个魅力!我一整天都在想这个问题。我希望我能投你更多的票。非常感谢!是的,这也解决了我的问题。UserSession.find总是返回nil。天哪!我一整天都在为此而挣扎。