ruby-on-rails – 如何在rails_admin的列表操作中显示图像?

我有一个自关联模型,允许用户定义“父照片”,以便将它们组合在一起.

我的模特:

class Photo < ActiveRecord::Base

  attr_accessible :image,:parent_photo

  has_attached_file :image,:styles => { :medium => "300x300>",:thumb => "100x100>" }

  validates_attachment :image,:presence => true,:size => { :in => 20..2000.kilobytes },:content_type => { :content_type => [ 'image/jpeg','image/png' ] }

  belongs_to :parent,class_name: "Photo",foreign_key: :parent_photo

  def associated_photos
    Photo.find_by_parent_photo(id)
  end

end

在我的rails_admin初始化程序中:

..

  config.model Photo do

    list do
      field :image
      field :associated_photos     
    end
  end
end

如何检索实际缩略图以在列表操作中使用?

解决方法

似乎这是在 the wiki的“字段 – 输出格式”标题解决的.

这样的事情会起作用吗?

config.model Photo do
  list do
    field :image do
      formatted_value do
        bindings[:view].tag(:img,{ :src => bindings[:object].image.url }) << value
      end
    field :associated_photos     
  end
end

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...