0

I want to show in objects list the icon 'active.ico' if created_at<1.day.ago else
show 'passive.ico'.How would I do that?

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 Answer 1

2

Use 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
Sign up to request clarification or add additional context in comments.

1 Comment

Then you need to adjust that code sample to your needs. For example, replace it by image_tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.