问题
I am using the Active Admin gem and I would like to hide or remove the links on the index page of each model allowing users to download data as CSV, XML or JSON. Is there any way to do this?
回答1:
There is now an option :download_links
on the index method, so you omit the download links if you want.
For example:
ActiveAdmin.register Post do
index :download_links => false do
# whatever
end
end
回答2:
You should use it as a option of index, but do not separate it from the column functions. Use it like this.
ActiveAdmin.register Post do
index :download_links => false do
column :title
column :body
end
end
Do not use it like this.This will let all your table columns is displayed, not the only that you specified by column function
index download_links: false
index do
column :title
column :body
end
回答3:
An alternative to the css fix above is this monkey patch:
module ActiveAdmin
module Views
class PaginatedCollection
def build_download_format_links(*args)
''
end
end
end
end
回答4:
For anyone hitting this page more recently who isn't happy with the answers, this works for me:
1: Hide all downloads:
app/admin/your_model.rb
ActiveAdmin.register YourModel do
index download_links: [nil]
...
2: Show only JSON. (Because why would you ever need anything else?):
app/admin/your_model.rb
ActiveAdmin.register YourModel do
index download_links: [:json]
...
3: It's an array y'all, so you can add in XML, CSV and more:
app/admin/your_model.rb
ActiveAdmin.register YourModel do
index download_links: [:json, :xml, :csv]
...
回答5:
ActiveAdmin doesn't allow this to be configured. Hack it using CSS.
In app/assets/stylesheets/active_admin.css.scss
.index #active_admin_content #index_footer {
color: white; // Hides the 'Download text'. Pagination links are styled on their own
a {
display: none; // Hides the CSV .. links
}
}
回答6:
Since you asked how to remove download links on each page, so the best to do say is to add the following line in config/initializers/active_admin.rb file.
config.namespace :admin do |admin|
admin.download_links = false
end
You can also specify where options you would like to have for downloading the data, like:
config.namespace :admin do |admin|
admin.download_links = [:pdf] # Now, it will only show PDF option.
end
Note: Don't forget to restart your server after you modify a config file.
来源:https://stackoverflow.com/questions/8928666/disable-csv-downloads-in-active-admin