Requires Active Admin to redirect to login page following the CSV download link
I am working on a cron task that emails a link to download a CSV file from Active Admin. The link looks like something like:
www.adminsite.com/admin/records.csv
If the user has not yet been authenticated in the system - the active administrator redirects to a page that simply says: "You need to login or register before proceeding." instead of being redirected to the login page and then after successfully authenticating with the CSV download link.
I tried looking at active internal admins but didn't get it yet. Any ideas?
Thank!
!!! EDIT !!!
I actually ended up solving this problem myself.
Since the link I generated was related to the CSV format, I had to add the devise.rb config file as: csv options as the navigation format :
config.navigational_formats = ["*/*", :html, :csv]
Now the redirect to the login page worked, but it was redirecting the user to /admin/login.csv which was returning as a blank page. I assume there was no template for the csv format.
I had to set up a redirect from /admin/login.csv to / admin / login by adding it to my routes.rb file :
devise_for :admin_users, ActiveAdmin::Devise.config do
match "/admin/login.csv" => redirect("/admin/login")
end
Done.
source to share
Active Admin uses the device to process its logins, so you probably didn't find anything.
From instructions here :
Create this class in 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
And add this to config / initializers / devise.rb:
config.warden do |manager|
manager.failure_app = CustomFailure
end
source to share