将音频播放器添加到活动管理面板

问题描述

我有一个Blog,该博客接受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的{​​{1}}?

解决方法

尝试显示带有导轨audio_tag助手(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