如何在活动管理员中将img标签转换为图像预览

时间:2014-05-29 15:37:03

标签: image ruby-on-rails-4 activeadmin formtastic

在Active Admin中,我有一个显示页面,如下所示:

show do |page|
    attributes_table do
      rows :id, :name
    end

    panel 'Sections' do
      attributes_table_for page.sections do
        rows :section, :content, :priority
      end
    end
    active_admin_comments
  end

'内容'上面代码中的字段可以有html' img'标签或只是一些文字内容。如果它包含img标签,我想显示图像的预览图像。我不知道如何在Active Admin中实现这一点。提前谢谢。

2 个答案:

答案 0 :(得分:0)

panel 'Sections' do
  attributes_table_for page.sections do
    row :section
    row :content do
       if page.content.includes? '<img'
         image_tag :content
       else
         :content
       end
    end
    row :priority
  end
end

或类似的。

答案 1 :(得分:0)

这对我有用:

panel 'Sections' do
      attributes_table_for page.sections do
        row :section
        row :content do |section|
          section.content.html_safe
        end
        row :priority
      end
    end
    active_admin_comments
  end