2
votes

User has many roles(name:string). For user form in ActiveAdmin i have following DSL-code (in app/admin/users.rb):

form do |f|
  f.inputs "Details" do
    f.input :email
    f.input :roles, as: :radio
  end
  f.buttons
end

Having two roles in db with names "basic" and "extended", it renders form with radio-buttons with labels "basic" and "extended", which are extracted from Role.name attribute.

I need to translate values of this attribute using I18n approach.

Can it be done using ActiveAdmin, or i should write my own partial for that?

Thanks!

1

1 Answers

5
votes

Consider something like this:

form do |f|
  f.inputs "Details" do
    f.input :email
    f.input :roles, :as => :radio, :collection => User.roles.map { |role| [I18n.t("active_admin.user.role.#{role.name}"), role.id] }
  end
  f.buttons
end