Skip to content
michaek edited this page Jun 14, 2012 · 5 revisions

The default initializer says "Try to avoid setting labels for models and attributes, use ActiveRecord I18n API instead." That's good advice! But what does it mean?

To start with, there's the documentation from Rails itself: http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models

Their example config will cause the user login field to display with "Handle" as its label:

en:
  activerecord:
    models:
      user: Dude
    attributes:
      user:
        login: "Handle"

Awesome!

But what about something like the help text? It would be cool to have something as robust as human_attribute_name to fetch the help text for the field, but something simpler could work as well.

In your initializer (rails_admin.rb), you could place:

config.models do
  edit do
    fields do
      help do
        I18n.t "admin.help.#{self.abstract_model.model_name.underscore}.#{self.name}", :help => help, :default => help
      end
    end
  end
end

That will add a configuration option to all your model to use the value from your localization, with the default help text as a default (and passed to the translation, for good measure) so you can do something like:

en:
  admin:
    help:
      user:
        login: "Enter your handle, please. %{help}"

Enjoy!

Clone this wiki locally