Ruby on rails 5 如何在RailsAdmin中显示ActiveStorage对象的文件名或自定义文本
我在RailsAdmin中包含了我的模型中的ActiveStorage属性,如下所示:Ruby on rails 5 如何在RailsAdmin中显示ActiveStorage对象的文件名或自定义文本,ruby-on-rails-5,rails-admin,Ruby On Rails 5,Rails Admin,我在RailsAdmin中包含了我的模型中的ActiveStorage属性,如下所示: config.model 'Employee' do list do field :resume, :active_storage end end field :resume, :active_storage do pretty_value do if value path = Rails.application.routes.url_help
config.model 'Employee' do
list do
field :resume, :active_storage
end
end
field :resume, :active_storage do
pretty_value do
if value
path = Rails.application.routes.url_helpers.rails_blob_path(value, only_path: true)
bindings[:view].content_tag(:a, value.filename, href: path)
end
end
这可以工作,但它会在列表视图中显示ActiveStorage对象:
我更愿意显示文件名或其他文本,同时仍然能够单击文本并下载文件。我的计算如下:
config.model 'Employee' do
list do
field :resume, :active_storage
end
end
field :resume, :active_storage do
pretty_value do
if value
path = Rails.application.routes.url_helpers.rails_blob_path(value, only_path: true)
bindings[:view].content_tag(:a, value.filename, href: path)
end
end