Rails_admin在列表中显示图像图标

时间:2014-02-13 12:36:02

标签: ruby-on-rails rails-admin

我想在对象列表中显示图标'active.ico'如果created_at< 1.day.ago else
显示'passive.ico'。我该怎么做?

RailsAdmin.config do |config|
  config.model Player do
    list do
      field :created_at do # (1)
        //if created_at<1.day show 'active.ico'
        //else show 'passive.ico'
      end
    end
  end
end

1 个答案:

答案 0 :(得分:1)

使用pretty_value

list do
  field :created_at do
    pretty_value do
      # result from here will be passed to a view
      if created_at = bindings[:object].try(:created_at)
        if created_at < 1.day
          image_tag("active.ico")  # <img alt="Icon" src="/assets/active.ico" />
        else
          image_tag("passive.ico") # <img alt="Icon" src="/assets/passive.ico" />
        end
      end
    end
  end
end