Ruby on rails 升级到rails 3.2后,gem“authlogic”堆栈级别太深
从“rails”、“2.3.15”升级到“rails”、“3.2.17”后,我遇到以下错误Ruby on rails 升级到rails 3.2后,gem“authlogic”堆栈级别太深,ruby-on-rails,ruby,ruby-on-rails-3,authlogic,Ruby On Rails,Ruby,Ruby On Rails 3,Authlogic,从“rails”、“2.3.15”升级到“rails”、“3.2.17”后,我遇到以下错误 Processing by HomeController#index as HTML Completed 500 Internal Server Error in 320.9ms SystemStackError (stack level too deep): .bundle/ruby/1.9.1/gems/actionpack-3.2.17/lib/action_dispatch/middlewa
Processing by HomeController#index as HTML
Completed 500 Internal Server Error in 320.9ms
SystemStackError (stack level too deep):
.bundle/ruby/1.9.1/gems/actionpack-3.2.17/lib/action_dispatch/middleware/reloader.rb:70
我知道错误在以下方法中的某个地方:
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
Authorization.current_user = @current_user
end
如果已经用rails 3实现了authlogic的人能给我一些提示,那就太棒了
非常感谢
这是我的完整应用程序控制器:
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
helper_method :current_user_session, :current_user
helper_method :current_user
helper_method :current_division
rescue_from Authorization::AttributeAuthorizationError, :with => :rescue_auth_error
protect_from_forgery # See ActionController::RequestForgeryProtection for details
# Scrub sensitive parameters from your log
around_filter :clear_current_user
before_filter :require_user
before_filter :configure_mailers
private
def rescue_auth_error(exception)
if current_user.present?
UserSession.find(current_user.id).destroy
flash[:error] = "Your session has expired. Please log in again."
redirect_to root_url
end
end
def clear_current_user
remove_instance_variable :@current_user if defined?(@current_user)
remove_instance_variable :@current_user_session if defined?(@current_user_session)
yield
remove_instance_variable :@current_user if defined?(@current_user)
remove_instance_variable :@current_user_session if defined?(@current_user_session)
Authorization.current_user = nil
end
def current_user_session
return @current_user_session if defined?(@current_user_session) && !@current_user_session.nil?
@current_user_session = UserSession.find
# @current_user_session = current_division.user_sessions.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
Authorization.current_user = @current_user
end
def require_user
unless current_user
store_location
# flash[:notice] = "You must be logged in to access this page"
redirect_to new_user_session_url
return false
end
end
def require_no_user
if current_user
store_location
# flash[:notice] = "You must be logged out to access this page"
redirect_to account_url
return false
end
end
def store_location
session[:return_to] = request.request_uri
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
def current_division
@current_division ||= Division.find_by_code('prd')
end
def configure_mailers
Notifier.configure(request)
end
def permission_denied
flash[:error] = "You do not have permission to access that page."
redirect_to root_url
end
end
此gem导致错误:
gem 'rd_searchlogic', :require => 'searchlogic', :git => 'git://github.com/railsdog/searchlogic.git'
替换为:
gem 'ransack'
现在一切都好了 authlogic的哪个版本?它是3.4.2版本,在rails升级后捆绑包更新了authlogic,听起来好像在运行一个无休止的循环,这是一个奇怪的错误。您使用的是哪个版本的ruby?我认为解决更新中出现的错误的最快方法通常是重新安装rails或ruby版本。如果你更新了rails,你可能也想更新ruby。我将ruby更新为1.9.3。。。这似乎是authlogic的一个问题:请注意,对于未来或您或其他人可能遇到的其他问题,rails 2.3.15到3.2.17是一个巨大的飞跃。我建议一次只测试一个版本,并在此过程中完全自动化和手动测试。对于许多应用程序,这是首选的不那么痛苦的路线。在您的示例中,我当然会先转到3.0,先不编译资产。我也会在这个过程中提前到Ruby 1.93.考虑到2.0.0。您大概希望rails版本接近于当时的ruby版本。否则,您可能最终不得不解决罕见的错误。