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

标签 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

关于ruby-on-rails - 如何在 rails_admin 的列表操作中显示图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11551214/

相关文章:

ruby-on-rails - Restful_authentication 与 Authlogic

ruby-on-rails - 为什么我的 rails 路线有点偏离?

ruby-on-rails - rails_admin 导航隐藏模型不起作用

ruby-on-rails - 在自定义 View 中使用 rails_admin 表单?

ruby-on-rails - Rubocop 唯一性验证应该使用唯一索引,在从某些特定值开始的值中

mysql - 多对多与一对多

ruby-on-rails - 有没有工具可以将 i18n yaml 文件转换为 gettext po 格式?

ruby-on-rails - Rails heroku app/assets/images 或上传到 AWS/Cloudinary

javascript - 如何禁用CKEditor的源代码 View ?

ruby-on-rails - Rails_admin 自定义 - 如何在自定义 Controller 中使用布局?