简体   繁体   English

Active Admin成功登录重定向到用户登录页面

[英]Active Admin Successful login redirect to User login page

We are facing a issue in active admin successful login the issue is after successful login active admin redirect to user login page ie http://localhost:3000/users/sign_in . 我们在主动管理成功登录时遇到问题,问题是在成功登录后,主动管理员重定向到用户登录页面,即http:// localhost:3000 / users / sign_in It was working fine earlier but all of sudden may be new update in active admin causing this issue because we have active admin in other projects too which were working fine until we update the gems with bundle and behaviour changed there too. 它工作得很好,但突然之间可能是活动管理员的新更新导致了这个问题,因为我们在其他项目中也有活跃的管理员工作正常,直到我们用bundle更新gems并且行为也发生了变化。 Any Suggestion ? 有什么建议吗? here is my config file 这是我的配置文件

ActiveAdmin.setup do |config|
  # == Site Title
  #
  # Set the title that is displayed on the main layout
  # for each of the active admin pages.
  #
  config.site_title = ENV['app_name']

  # Set the link url for the title. For example, to take
  # users to your main site. Defaults to no link.
  #
  # config.site_title_link = "/"

  # Set an optional image to be displayed for the header
  # instead of a string (overrides :site_title)
  #
  # Note: Aim for an image that's 21px high so it fits in the header.
  #
  config.before_filter :set_admin_timezone
  config.site_title_image = "admin-logo.png"

  # == Default Namespace
  #
  # Set the default namespace each administration resource
  # will be added to.
  #
  # eg:
  #   config.default_namespace = :hello_world
  #
  # This will create resources in the HelloWorld module and
  # will namespace routes to /hello_world/*
  #
  # To set no namespace by default, use:
  #   config.default_namespace = false
  #
  # Default:
  # config.default_namespace = :admin
  #
  # You can customize the settings for each namespace by using
  # a namespace block. For example, to change the site title
  # within a namespace:
  #
  #   config.namespace :admin do |admin|
  #     admin.site_title = "Custom Admin Title"
  #   end
  #
  # This will ONLY change the title for the admin section. Other
  # namespaces will continue to use the main "site_title" configuration.

  # == User Authentication
  #
  # Active Admin will automatically call an authentication
  # method in a before filter of all controller actions to
  # ensure that there is a currently logged in admin user.
  #
  # This setting changes the method which Active Admin calls
  # within the application controller.
  config.authentication_method = :authenticate_admin_user!

  # == User Authorization
  #
  # Active Admin will automatically call an authorization
  # method in a before filter of all controller actions to
  # ensure that there is a user with proper rights. You can use
  # CanCanAdapter or make your own. Please refer to documentation.
  # config.authorization_adapter = ActiveAdmin::CanCanAdapter

  # In case you prefer Pundit over other solutions you can here pass
  # the name of default policy class. This policy will be used in every
  # case when Pundit is unable to find suitable policy.
  # config.pundit_default_policy = "MyDefaultPunditPolicy"

  # You can customize your CanCan Ability class name here.
  # config.cancan_ability_class = "Ability"

  # You can specify a method to be called on unauthorized access.
  # This is necessary in order to prevent a redirect loop which happens
  # because, by default, user gets redirected to Dashboard. If user
  # doesn't have access to Dashboard, he'll end up in a redirect loop.
  # Method provided here should be defined in application_controller.rb.
  # config.on_unauthorized_access = :access_denied

  # == Current User
  #
  # Active Admin will associate actions with the current
  # user performing them.
  #
  # This setting changes the method which Active Admin calls
  # (within the application controller) to return the currently logged in user.
  config.current_user_method = :current_admin_user

  # == Logging Out
  #
  # Active Admin displays a logout link on each screen. These
  # settings configure the location and method used for the link.
  #
  # This setting changes the path where the link points to. If it's
  # a string, the strings is used as the path. If it's a Symbol, we
  # will call the method to return the path.
  #
  # Default:
  config.logout_link_path = :destroy_admin_user_session_path

  # This setting changes the http method used when rendering the
  # link. For example :get, :delete, :put, etc..
  #
  # Default:
  config.logout_link_method = :delete

  # == Root
  #
  # Set the action to call for the root path. You can set different
  # roots for each namespace.
  #
  # Default:
   config.root_to = 'tenants#index'

  # == Admin Comments
  #
  # This allows your users to comment on any resource registered with Active Admin.
  #
  # You can completely disable comments:
  config.comments = false
  #
  # You can change the name under which comments are registered:
  # config.comments_registration_name = 'AdminComment'
  #
  # You can change the order for the comments and you can change the column
  # to be used for ordering:
  # config.comments_order = 'created_at ASC'
  #
  # You can disable the menu item for the comments index page:
  # config.comments_menu = false
  #
  # You can customize the comment menu:
  # config.comments_menu = { parent: 'Admin', priority: 1 }

  # == Batch Actions
  #
  # Enable and disable Batch Actions
  #
  config.batch_actions = false

  # == Controller Filters
  #
  # You can add before, after and around filters to all of your
  # Active Admin resources and pages from here.
  #
  # config.before_action :do_something_awesome

  # == Localize Date/Time Format
  #
  # Set the localize format to display dates and times.
  # To understand how to localize your app with I18n, read more at
  # https://github.com/svenfuchs/i18n/blob/master/lib%2Fi18n%2Fbackend%2Fbase.rb#L52
  #
  config.localize_format = :long

  # == Setting a Favicon
  #
  # config.favicon = 'favicon.ico'

  # == Meta Tags
  #
  # Add additional meta tags to the head element of active admin pages.
  #
  # Add tags to all pages logged in users see:
  #   config.meta_tags = { author: 'My Company' }

  # By default, sign up/sign in/recover password pages are excluded
  # from showing up in search engine results by adding a robots meta
  # tag. You can reset the hash of meta tags included in logged out
  # pages:
  #   config.meta_tags_for_logged_out_pages = {}

  # == Removing Breadcrumbs
  #
  # Breadcrumbs are enabled by default. You can customize them for individual
  # resources or you can disable them globally from here.
  #
  config.breadcrumb = false

  # == Create Another Checkbox
  #
  # Create another checkbox is disabled by default. You can customize it for individual
  # resources or you can enable them globally from here.
  #
  # config.create_another = true

  # == Register Stylesheets & Javascripts
  #
  # We recommend using the built in Active Admin layout and loading
  # up your own stylesheets / javascripts to customize the look
  # and feel.
  #
  # To load a stylesheet:
  #   config.register_stylesheet 'my_stylesheet.css'
  #
  # You can provide an options hash for more control, which is passed along to stylesheet_link_tag():
  #   config.register_stylesheet 'my_print_stylesheet.css', media: :print
  #
  # To load a javascript file:
  #   config.register_javascript 'my_javascript.js'

  # == CSV options
  #
  # Set the CSV builder separator
  # config.csv_options = { col_sep: ';' }
  #
  # Force the use of quotes
  # config.csv_options = { force_quotes: true }

  # == Menu System
  #
  # You can add a navigation menu to be used in your application, or configure a provided menu
  #
  # To change the default utility navigation to show a link to your website & a logout btn
  #
  #   config.namespace :admin do |admin|
  #     admin.build_menu :utility_navigation do |menu|
  #       menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
  #       admin.add_logout_button_to_menu menu
  #     end
  #   end
  #
  # If you wanted to add a static menu item to the default menu provided:
  #
  #   config.namespace :admin do |admin|
  #     admin.build_menu :default do |menu|
  #       menu.add label: "My Great Website", url: "http://www.mygreatwebsite.com", html_options: { target: :blank }
  #     end
  #   end

  # == Download Links
  #
  # You can disable download links on resource listing pages,
  # or customize the formats shown per namespace/globally
  #
  # To disable/customize for the :admin namespace:
  #
     config.namespace :admin do |admin|
  #
  #     # Disable the links entirely
       admin.download_links = false
  #
  #     # Only show XML & PDF options
  #     admin.download_links = [:xml, :pdf]
  #
  #     # Enable/disable the links based on block
  #     #   (for example, with cancan)
  #     admin.download_links = proc { can?(:view_download_links) }
  #
     end

  # == Pagination
  #
  # Pagination is enabled by default for all resources.
  # You can control the default per page count for all resources here.
  #
  config.default_per_page = 30
  #
  # You can control the max per page count too.
  #
  config.max_per_page = 100

  # == Filters
  #
  # By default the index screen includes a "Filters" sidebar on the right
  # hand side with a filter for each attribute of the registered model.
  # You can enable or disable them for all resources here.
  #
  # config.filters = true
  #
  # By default the filters include associations in a select, which means
  # that every record will be loaded for each association.
  # You can enabled or disable the inclusion
  # of those filters by default here.
  #
  # config.include_default_association_filters = true

  # == Footer
  #
  # By default, the footer shows the current Active Admin version. You can
  # override the content of the footer here.
  #
  config.footer = 'Powered by abc.com'

  # == Sorting
  #
  # By default ActiveAdmin::OrderClause is used for sorting logic
  # You can inherit it with own class and inject it for all resources
  #
  # config.order_clause = MyOrderClause

  config.clear_stylesheets!
  config.register_stylesheet 'admin/active_admin.css'

  config.clear_javascripts!
  config.register_javascript 'admin/active_admin.js'
end

In routes.rb what you can do is change sessions controller pointed to by ActiveAdmin::Devise.config , which among other things (by default) returns :controllers=> {:sessions=>"active_admin/devise/sessions", ... } . routes.rb中 ,您可以做的是更改ActiveAdmin::Devise.config指向的会话控制器,其中(默认情况下)返回:controllers=> {:sessions=>"active_admin/devise/sessions", ... } In ActiveAdmin 1.0.0.pre1 these controllers can be found in activeadmin-1.0.0.pre1/lib/active_admin/devise.rb . 在ActiveAdmin 1.0.0.pre1中,可以在activeadmin-1.0.0.pre1/lib/active_admin/devise.rb找到这些控制器。 You can set your sessions_controller like this: devise_for :admin_users, ActiveAdmin::Devise.config.deep_merge(controllers: { sessions: "some/custom/path/sessions" }) , note that other configuration remains the same. 您可以像这样设置sessions_controllerdevise_for :admin_users, ActiveAdmin::Devise.config.deep_merge(controllers: { sessions: "some/custom/path/sessions" }) ,请注意其他配置保持不变。 Then you must create your sessions_controller.rb in some/custom/path eg: 然后你必须在some/custom/path创建你的sessions_controller.rb ,例如:

class Some::Custom::Path::SessionsController < Devise::SessionsController
  # As can be seen in 'activeadmin/lib/active_admin/devise.rb'
  include ::ActiveAdmin::Devise::Controller

  def after_sign_in_path_for(resource)
    "your/custom/path"
  end
end

Maybe someone has better solution but here is a quick patch for your problem. 也许有人有更好的解决方案,但这里是你的问题的快速补丁。

At bottom of your config/active_admin.rb , add the following code. config/active_admin.rb底部,添加以下代码。

Assuming that you've registered your Admin users like this in routes.rb 假设您已在routes.rb注册了这样的管理员用户

devise_for :admin_users, ActiveAdmin::Devise.config 
ActiveAdmin.routes(self)

class ActiveAdmin::Devise::SessionsController 

 def after_sign_in_path_for(resource)
  case resource
   when AdminUser then '/admin'
    else super
  end
 end

 def after_sign_out_path_for(resource)
  '/admin'
 end
end

Note: Server Restart is needed whenever you made any change in this file. 注意:只要在此文件中进行任何更改,就需要重新启动服务器。

For reference and possible issues read this Activeadmin Github Issues 有关参考和可能的问题,请阅读此Activeadmin Github问题

Post your Gemfile.lock. 发布您的Gemfile.lock。 If you are using Devise make sure it is a recent version. 如果您正在使用Devise,请确保它是最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM