ruby-on-rails-5 - 如何在 RailsAdmin 中显示 ActiveStorage 对象的文件名或自定义文本
问题描述
我在 RailsAdmin 中包含了我的模型中的 ActiveStorage 属性,如下所示:
config.model 'Employee' do
list do
field :resume, :active_storage
end
end
这有效,但它在列表视图中显示 ActiveStorage 对象:
我宁愿显示文件名或其他一些文本,同时仍然能够单击文本并下载文件。
解决方案
我想通了如下:
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
推荐阅读
- ionic-framework - 错误类型错误:无法读取未定义的属性“文档”
- ruby-on-rails - 将 Sidekiq 升级到 v6 后,它不会在生产环境中自动启动
- javascript - Recharts 垂直渲染饼图
- c++ - 如何使用c ++获取在给定目录中创建的最新文件夹的名称
- java - 简单的 Spring Boot 微服务 - 内存使用消耗超过 300 MB
- javascript - 修复显示中的背景线性颜色:flex 溢出滚动内容 - CSS
- ruby-on-rails - Stripe SCA 一次性付款 Rails
- javascript - 如何在 Reactjs 中的功能组件之间传递值?
- r - 使用具有不均匀输出 R 的 df 列创建日期范围向量
- python - 如何避免超出“while”中的时间限制?(Python)