无法在 Rails 3.0.1 上使用 Authlogic 设置 current_user [英] Not able to set a current_user using Authlogic on Rails 3.0.1
问题描述
我在 Rails 2.3.5 上完美运行了官方 authlogic 插件.我将应用程序转换为 Rails 3.0.1,但现在遇到了一些问题.
I had the official authlogic plugin running perfectly on Rails 2.3.5. I converted my application to Rails 3.0.1 and now I'm having some problems.
我在我的 gemfile 中包含了以下 authlogic gemgem 'authlogic', :git =>'git://github.com/odorcicd/authlogic.git', :branch =>'rails3'
I've included the following authlogic gem in my gemfile
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
当用户登录时,会话被保存.调用该用户会话时,返回值为 nil.UserSession.find 返回一个 nil 值
所以我不能分配一个 current_user.
When a user logs in, the session is saved. When calling that user session, the returned value is nil. UserSession.find returns a nil value
so I'm not able to assign a current_user.
sessions_controller.rb
sessions_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
application_controller.rb
application_controller.rb
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
当用户登录时,会返回带有 'Login sucessful'
的 flash 通知,但未设置 current_user.我也用官方的 authlogic 插件试过这个,没有任何改变.我在这里遗漏了什么吗?
When a user logs in, the flash notice is returned with 'Login sucessful'
but the current_user isn't set. I've also tried this with the official authlogic plugin and nothing changed. Am I missing something here?
谢谢!
蒂姆
推荐答案
我确实遇到了这个问题.出于某种原因,它干扰了基本身份验证 - 为了修复它,我将 allow_http_basic_auth 设置为 false.
I had this exact problem. For some reason it was interfering with basic auth - to fix it I set allow_http_basic_auth to false.
class UserSession < Authlogic::Session::Base
allow_http_basic_auth false
end
这篇关于无法在 Rails 3.0.1 上使用 Authlogic 设置 current_user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!