New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove NameError rescue in page base #920
Conversation
spec/example_app/db/migrate/20170702033920_add_timestamp_to_payments.rb
Outdated
Show resolved
Hide resolved
The rescue statement generates a false positive on payments feature specs, the timestamps migrations are created to fix this. |
This looks good! Could I get you to fix the Hound comment above? |
0034f0f
to
bcb6d1a
Compare
Stale :-( Happy to see this reopen if someone wants to take over. |
Actually, I thought better of this one. I'm going to try see it through. |
This PR appears to break any support for virtual fields by enforcing the the resource must define a method to respond to all keys in the class ReportDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
id: Field::Number,
filename: Field::String,
mimetype: Field::String,
s3_key: Field::String,
download: S3DownloadField.with_options({ download_path: :download_lab_report_path }),
page_count: Field::Number,
created_at: Field::DateTime,
updated_at: Field::DateTime
}.freeze
COLLECTION_ATTRIBUTES = [
:id,
:filename,
:download,
:mimetype,
:created_at
].freeze
SHOW_PAGE_ATTRIBUTES = [
:id,
:download,
:filename,
:mimetype,
:s3_key,
:page_count,
:created_at,
:updated_at
].freeze
FORM_ATTRIBUTES = [
:lab,
:filename,
:mimetype,
:s3_key,
:page_count
].freeze
end class S3DownloadField < Administrate::Field::Base
def to_s
data
end
def downloadable?
options.key?(:download_path)
end
def destroyable?
options.key?(:destroy_path)
end
def destroy_path(field, attachment)
path_helper(:destroy_path, field, attachment)
end
def download_path(field, attachment)
path_helper(:download_path, field, attachment)
end
private
def path_helper(key, field, _attachment)
path_helper = options.fetch(key)
Rails.application.routes.url_helpers.send(path_helper, field.resource)
end
end This allowed us to inject a download link for our S3 resource without editing the underlying views, or modifying the display for any of the actual attributes. Is there any advice on how to fix this without defining useless methods on our models? |
Fixes #480