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

问题描述

我有一个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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...