Rails Admin - only display field on edit

Conditionally displaying fields only if they are present in the database

Here’s how we used Rails Admin to only allow a field to be shown after creation.

We have a client who wanted the ability to be able to edit slugs (appropriate warnings were given about how this can be a bad thing!). We only wanted this field to be visible on edit in Rails Admin as we normally generate our slugs from the model’s title attribute.

RailsAdmin.config do |config|
  config.model Article do 
    edit do 
      field :slug do 
        visible do 
          bindings[:object].slug.present?
        end
        help "WARNING, if you edit this - old links to the article WILL break" # just in case they forget!
      end
    end
  end
end 

Recent posts View all

Ruby

Forcing a Rails database column to be not null

How you can force a table column to always have something in it with Rails

Writing Marketing

We've deleted an article's worth of unhelpful words

We've improved several pages across our site by removing words that add no value, and often detract from the article.