【问题标题】:How to convert img tag to image preview in active admin如何在活动管理员中将 img 标签转换为图像预览
【发布时间】:2014-05-29 15:37:03
【问题描述】:

在 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

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

【问题讨论】:

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


    【解决方案1】:
    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
    

    或类似的。

    【讨论】:

      【解决方案2】:

      这对我有用:

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-06
        • 1970-01-01
        • 2017-02-04
        • 2013-10-28
        • 2017-03-31
        • 2014-08-28
        • 2017-04-04
        相关资源
        最近更新 更多