ruby-on-rails - 将音频播放器添加到活动管理面板
问题描述
我有一个博客,它接受带有 Rails 6 附带的音频文件的评论。
是否可以在活动的管理仪表板中显示音频并收听它们?
我有
#/models/comment.rb
class Comment < ApplicationRecord
belongs_to :post
belongs_to :user
has_one_attached :audio_file
end
#/admin/comments.rb
ActiveAdmin.register Comment do
actions :all, except: [:edit, :new]
permit_params :audio_file, :post_id, :created_at, :deleted_by
end
我尝试添加
index do
selectable_column
id_column
column :audio_file
column :challenge_id
column :created_at
column :deleted_by
actions
end
但它只是添加文本audio_file
。
如何添加audio_tag
附件audio_file
?
解决方案
尝试使用 rails audio_tag
helper ( https://apidock.com/rails/ActionView/Helpers/AssetTagHelper/audio_tag ) 显示音频标签,如下所示。
index do
selectable_column
id_column
column :audio_file do |comment|
if comment.audio_file.attached?
audio_tag(comment.audio_file, autoplay: true, controls: true)
else
# Do whatever needed
end
end
column :challenge_id
column :created_at
column :deleted_by
actions
end
推荐阅读
- wysiwyg - Pimcore 内容编辑器删除
标签 - azure - 如何通过 Java 以编程方式在 Azure 搜索中设置认知搜索功能(使用 OCR)?
- google-cloud-platform - GCP Pub/Sub:如何在 PublishCallbackListener 的 onFailure() 中获取事件详细信息
- python - 使用 SageMath 在 Python 中对非常大的整数进行除法
- mysql - 子查询中多行的比较
- python - 向最终用户显示 FastAPI 验证错误
- php - 从另一个文件获取 JSON 变量的问题
- java - 如何从 java 程序运行 jhipster 命令
- html - HTML 网格数字列边框颜色
- json - 在调用 Api 时将类映射到 json,在颤动中显示错误