【问题标题】:Filter chain halted as :redirect_admin rendered or redirected过滤器链因 :redirect_admin 呈现或重定向而停止
【发布时间】:2017-02-11 16:34:09
【问题描述】:

当我尝试登录我的 Rails 应用程序时,我在日志中收到以下错误:

I, [2016-10-03T11:44:17.136518 #13441]  INFO -- : Started GET "/" for 72.238.233.104 at 2016-10-03 11:44:17 -0500
I, [2016-10-03T11:44:17.139196 #13441]  INFO -- : Processing by PagesController#home as HTML
I, [2016-10-03T11:44:17.144634 #13441]  INFO -- : Redirected to https://www.myserver.org/admin/
I, [2016-10-03T11:44:17.144741 #13441]  INFO -- : Filter chain halted as :redirect_admin rendered or redirected
I, [2016-10-03T11:44:17.144949 #13441]  INFO -- : Completed 302 Found in 6ms (ActiveRecord: 1.8ms)
I, [2016-10-03T11:44:17.394535 #13441]  INFO -- : Started GET "/admin/" for 72.238.233.104 at 2016-10-03 11:44:17 -0500
I, [2016-10-03T11:44:17.396819 #13441]  INFO -- : Processing by RailsAdmin::MainController#dashboard as HTML
I, [2016-10-03T11:44:17.402503 #13441]  INFO -- : Redirected to https://www.myserver.org/
I, [2016-10-03T11:44:17.402686 #13441]  INFO -- : Completed 302 Found in 6ms (ActiveRecord: 1.6ms)
I, [2016-10-03T11:44:17.650009 #13477]  INFO -- : Started GET "/" for 72.238.233.104 at 2016-10-03 11:44:17 -0500
I, [2016-10-03T11:44:17.651967 #13477]  INFO -- : Processing by PagesController#home as HTML
I, [2016-10-03T11:44:17.657941 #13477]  INFO -- : Redirected to https://www.myserver.org/admin/
I, [2016-10-03T11:44:17.658051 #13477]  INFO -- : Filter chain halted as :redirect_admin rendered or redirected
I, [2016-10-03T11:44:17.658498 #13477]  INFO -- : Completed 302 Found in 6ms (ActiveRecord: 1.8ms)
I, [2016-10-03T11:44:17.909178 #13483]  INFO -- : Started GET "/admin/" for 72.238.233.104 at 2016-10-03 11:44:17 -0500
I, [2016-10-03T11:44:17.911936 #13483]  INFO -- : Processing by RailsAdmin::MainController#dashboard as HTML
I, [2016-10-03T11:44:17.917690 #13483]  INFO -- : Redirected to https://www.myserver.org/
I, [2016-10-03T11:44:17.917845 #13483]  INFO -- : Completed 302 Found in 6ms (ActiveRecord: 1.9ms)

在浏览器窗口中我得到:

The www.myserver.com page isn’t working

www.myserver.com redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS

从哪里开始排除故障?

我使用 Rails_Admin gem 进行管理,使用 Devise 进行身份验证

谢谢!

更新: 这是我的注册控制器:

class Users::RegistrationsController < Devise::RegistrationsController
before_action :get_company_and_locations, only: [:edit, :update]

   def edit
     @card = get_stripe_info_by_customer(current_user.company.stripe_id)
     @last4 = @card.last4
     @exp_month = @card.exp_month
     @exp_year = @card.exp_year
   end

  # PUT /resource
  def update
    @user = User.find(current_user.id)
    if @user.update_with_password(user_params)
      sign_in @user, :bypass => true
      redirect_to :back
      flash[:success] = "Your profile has been updated successfully!"
    else
      redirect_to :back
    end
  end


  private

  def user_params
    # NOTE: Using `strong_parameters` gem
    params.require(:user).permit(:email, :first_name, :last_name, :phone_number, :password, :password_confirmation, :current_password, :enable_notifications, :time_zone, :avatar)
  end

  def sign_up_params
    params.require(:user).permit(:email, :first_name, :last_name, :phone_number, :password, :password_confirmation, :enable_notifications, :time_zone)
  end

  def account_update_params
    params.require(:user).permit(:email, :first_name, :last_name, :phone_number, :password, :password_confirmation, :current_password, :enable_notifications, :time_zone)
  end

  def after_inactive_sign_up_path_for(resource)
    new_user_session_path
  end

end

更新: 看起来特定于以管理员身份登录的控制器位于application_controller,所以,这是文件:

class ApplicationController < ActionController::Base
  include ApplicationHelper

  protect_from_forgery with: :null_session, if: ->(controller) { controller.request.format == "application/json" }

  before_filter :configure_permitted_parameters, if: :devise_controller?


  before_action :authenticate_user_from_token!
  before_action :authenticate_user!
  before_action :redirect_admin
  around_action :set_time_zone


  layout :layout_by_resource

  private

  def redirect_admin
    if current_user && current_user.admin? && !rails_admin_controller? && !devise_controller?
      redirect_to rails_admin.dashboard_path
    end
  end

我认为:redirect_admin 是我的问题,因为这是日志中提到的,但我不明白为什么......

【问题讨论】:

  • 你能通过你的控制器代码吗?
  • 当然,@SantoshSharma 是哪个控制器?我的设计文件夹下没有sessions_controller(从来没有),只有一个registrations
  • 过去你的registrations控制器
  • @SantoshSharma 添加了registrations and application controllers
  • 谢谢。我正在看。

标签: ruby-on-rails ruby devise rails-admin


【解决方案1】:

哇...所以,完全随机,但我决定为我的管理员用户更改时区。现在我可以登录了。

【讨论】:

    猜你喜欢
    • 2016-02-25
    • 2018-10-08
    • 1970-01-01
    • 2012-09-19
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多