[英]rails 3 routes stack level too deep devise
I get this error about my routes file 我收到有关我的路线文件的错误
SystemStackError (stack level too deep):
actionpack (3.2.8) lib/action_dispatch/middleware/reloader.rb:70
Rendered /Users/duy/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.5ms)
Rendered /Users/duy/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.3ms)
Rendered /Users/duy/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (19.9ms)
I could isolate the problematic code but don't understand what's creating the infinite loop: 我可以隔离有问题的代码,但不明白是什么创建了无限循环:
devise_for :users, :controllers => { :registrations => "registrations", :sessions => "sessions", :omniauth_callbacks => "users/omniauth_callbacks" }
devise_scope :user do
match '/sessions/simulate_user/:id' => 'sessions#simulate_user', :as => :simulate_user_sessions
match '/sessions/leave_simulation_mode' => 'sessions#leave_simulation_mode', :as => :leave_simulation_mode_sessions
get "user_confirmation", :to => "devise/confirmations#create"
get "after_confirmation", :to => "challenges#index"
end
Any help would be greatly appreciated! 任何帮助将不胜感激!
EDIT: 编辑:
class SessionsController < Devise::SessionsController
def new
@after_sign_in_page = params[:after_sign_in_page] if params[:after_sign_in_page]
super
end
def create
params[:user][:email].downcase!
super
end
def simulate_user
if can? :simulate_user, User
admin = current_user.id
sign_out
@user = User.find(params[:id])
if sign_in @user
session[:simulation_for] = admin
redirect_to request.referer
else
flash[:notice] = "Something went wrong"
redirect_to action: "leave_simulation_mode"
end
end
end
def leave_simulation_mode
@user = User.find(session[:simulation_for])
sign_out
if sign_in @user
session[:simulation_for] = nil
else
flash[:notice] = "something went wrong..."
end
redirect_to request.referer
end
end
class ChallengesController < ApplicationController
def index
params[:format] = "html" unless params[:subaction].nil?
@video = true unless user_signed_in?
if current_user
@current_page = params[:page] ? params[:page].to_i : 1
@columns = params[:cols] ? params[:cols] : 2
@keyword = params[:keyword]
@search = true if params[:search] == "1"
@challenges = Challenge.is_open.where(id: current_user.challenges.filtered(params[:keyword],params[:user],params[:expertize]).collect(&:root_id).uniq)
logger.debug "Challenges found: #{@challenges.count}"
@users = User.scoped
@expertizes = Expertize.all
end
respond_to do |format|
format.html {
if current_user
if current_user.challenges.waiting_for_approval.count == 1 and @challenges.count == 1
redirect_to challenge_path(current_user.challenges.waiting_for_approval.first, subaction: "description")
return
logger.debug "REdirect called"
else
@challenges = @challenges.page(1).per(@current_page.to_i * 10).order('children_count+tasks_count desc')
end
end
render
}
format.json { render json: @challenges }
format.js {
@challenges = @challenges.page(@current_page).per(10).order('children_count+tasks_count desc')
render
}
end
end
end
Also, I forgot to mention that when I restart the local server, it works fine. 另外,我忘了提到当我重新启动本地服务器时,它工作正常。 Every time I change my routes.rb file, I get this error. 每次我更改routes.rb文件时,都会收到此错误。 Then I have to restart the Thin server, then I can work further on... 然后我必须重新启动瘦服务器,然后我可以继续...
EDIT 2: 编辑2:
rake route output: https://www.dropbox.com/s/knmkk1f54vx47yj/rake%20routes.rtf rake route输出: https : //www.dropbox.com/s/knmkk1f54vx47yj/rake%20routes.rtf
I have a same problem with you. 我和你有同样的问题。 This must be a issue caused by some gems. 这必定是一些宝石造成的问题。
Like I use "devise_invitable" with "devise". 就像我用“devise_invitable”和“devise”一样。 then every time I modified route file in development environment. 然后每次我在开发环境中修改路由文件。 it will raise an "stack too deep" error from "lib/action_dispatch/middleware/reloader.rb". 它会从“lib / action_dispatch / middleware / reloader.rb”引发“堆栈太深”的错误。
After reading your post. 看完你的帖子。 I try to comment devise_for :users. 我试着评论devise_for:users。 Reload routes is ok. 重新加载路线是好的。
Then I try to remove "devise_invitable" from Gemfile. 然后我尝试从Gemfile中删除“devise_invitable”。
After made changes. 经过改动。 it doesn't raise error. 它不会引起错误。 This happend after I use Rails 3.2.9. 这是在我使用Rails 3.2.9之后发生的。 I have another project < Rails 3.2.9, two gems works correct. 我有另一个项目<Rails 3.2.9,两个宝石的工作正确。
I'm only guessing, but your construct of SessionsController#simulate_user
and SessionsController#leave_simulation_mode
exposes an infinite redirection loop. 我只是猜测,但你的SessionsController#simulate_user
和SessionsController#leave_simulation_mode
暴露了一个无限的重定向循环。
If you access the url /simulate_user
and the sign in doesn't work (else path) you redirect to /leave_simulation_mode
. 如果您访问url /simulate_user
并且登录无效(否则路径),则重定向到/leave_simulation_mode
。 Now in leave_simulation_mode
, no matter if the sign out/sign in works or not you redirect back to /simulate_user
again, due to redirect_to request.referer
. 现在在leave_simulation_mode
,无论登出/登录是否有效,由于redirect_to request.referer
,您再次重定向回/simulate_user
。
Now back in /simulate_user
, the user is signed in again, failing again --> redirecting again. 现在回到/simulate_user
,用户再次登录,再次失败 - >再次重定向。
If something's blocking your simulated user from being signed in correctly, you got an infinite redirection loop: 如果有什么东西阻止你的模拟用户正确登录,你会得到一个无限的重定向循环:
simulate_user -> leave_simulation_mode -> simulate_user -> leave_simulation_mode --> ...
Hope that helps! 希望有所帮助!
Move all monkeypatches to initalizers. 将所有monkeypatches移动到initalizers。
I have the same problem due to monkeypatching of ActionDispatch::Request. 由于ActionDispatch :: Request的monkeypatching,我遇到了同样的问题。 Patch was placed to base controller. 补丁被放置到基础控制器。 When I replace it to initializers, issue was fixed. 当我将其替换为初始化程序时,问题已修复。
It's not clear from the other answers, but this was a bug in devise_invitable gem that was fixed in version 1.1.5. 从其他答案中不清楚,但这是版本1.1.5中修复的devise_invitable gem中的一个错误。 Here's the issue on GitHub: https://github.com/scambra/devise_invitable/issues/252 以下是GitHub上的问题: https : //github.com/scambra/devise_invitable/issues/252
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.