4

I'm working on a cron task that e-mails out a link to download a CSV file from Active Admin. The link looks like something along the lines of: www.adminsite.com/admin/records.csv

If the user isn't already authenticated into the system -- active admin redirects to the page that just says "You need to sign in or sign up before continuing." instead of redirecting to the login page and then following through with a CSV download link upon successful authentication.

I've tried looking into active admin internals, but have not been able to figure it out yet. Any ideas?

Thanks!

!!! EDIT !!!

I actually ended up solving this issue on my own.

Because the link I was generating was navigating to a csv format, I had to add in the :csv option as a navigational format to devise.rb configuration file:

config.navigational_formats = ["*/*", :html, :csv]

Now the redirect to the login page was working, but it was taking the user to /admin/login.csv, which was coming back as an empty page. I'm assuming there was no template for a csv format.

I had to set up the redirect from /admin/login.csv to /admin/login by adding this to the routes.rb file:

 devise_for :admin_users, ActiveAdmin::Devise.config do
    match "/admin/login.csv" => redirect("/admin/login")
  end

Done.

4

1 回答 1

0

Active Admin 使用设计来处理其登录,这可能就是您找不到任何东西的原因。

这里的说明:

在 lib/custom_failure.rb 中创建此类:

class CustomFailure < Devise::FailureApp
  def redirect_url
    #return super unless [:worker, :employer, :user].include?(scope) #make it specific to a scope
     new_user_session_url(:subdomain => 'secure')
  end

  # You need to override respond to eliminate recall
  def respond
    if http_auth?
      http_auth
    else
      redirect
    end
  end
end

并将其添加到 config/initializers/devise.rb:

config.warden do |manager|
  manager.failure_app = CustomFailure
end
于 2013-02-09T22:07:34.717 回答