11

我收到有关我的路线文件的此错误

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)

我可以隔离有问题的代码,但不明白是什么造成了无限循环:

  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

任何帮助将不胜感激!

编辑:

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

另外,我忘了提到当我重新启动本地服务器时,它工作正常。每次我更改我的 routes.rb 文件时,我都会收到此错误。然后我必须重新启动瘦服务器,然后我才能继续工作......

编辑2:

rake 路由输出:h​​ttps ://www.dropbox.com/s/knmkk1f54vx47yj/rake%20routes.rtf

4

4 回答 4

5

我和你有同样的问题。这一定是某些宝石引起的问题。

就像我将“devise_invitable”与“devise”一起使用。然后每次我在开发环境中修改路由文件。它将从“lib/action_dispatch/middleware/reloader.rb”引发“堆栈太深”错误。

看完你的帖子。我尝试评论 devise_for :users。重新加载路线就可以了。

然后我尝试从 Gemfile 中删除“devise_invitable”。

修改后。它不会引发错误。这发生在我使用 Rails 3.2.9 之后。我有另一个项目< Rails 3.2.9,两个宝石工作正常。

于 2013-01-11T07:28:25.060 回答
2

我只是在猜测,但是您构造SessionsController#simulate_userSessionsController#leave_simulation_mode公开了无限重定向循环。

如果您访问 url/simulate_user并且登录不起作用(其他路径),您将重定向到/leave_simulation_mode. 现在leave_simulation_mode,无论退出/登录是否有效,您都会/simulate_user再次重定向回,因为redirect_to request.referer.

现在重新/simulate_user登录,用户再次登录,再次失败 --> 再次重定向。

如果某些东西阻止您的模拟用户正确登录,您将获得一个无限重定向循环:

simulate_user -> leave_simulation_mode -> simulate_user -> leave_simulation_mode --> ...

希望有帮助!

于 2012-12-31T11:04:08.120 回答
1

将所有猴子补丁移动到初始化程序。

由于 ActionDispatch::Request 的猴子补丁,我遇到了同样的问题。补丁被放置到基本控制器。当我将其替换为初始化程序时,问题已解决。

于 2013-03-27T13:56:05.947 回答
0

从其他答案中不清楚,但这是 devise_invitable gem 中的一个错误,已在 1.1.5 版中修复。这是 GitHub 上的问题:https ://github.com/scambra/devise_invitable/issues/252

于 2013-01-31T22:51:47.990 回答