4

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

我的模型:

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

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

4

2 回答 2

9

这似乎在 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
于 2012-07-26T23:59:59.877 回答
5

要显示图像字段:

config.model Photo do
  list do
    field :image do
      pretty_value do
        bindings[:view].tag(:img, { :src => bindings[:object].image.url(:thumb) })
      end
    end
  end
end
于 2016-02-02T17:07:20.437 回答