Reputation: 4572
I'm using Rails 4.2.5 and the latest version of ActiveAdmin in a Rails test project. I would like to rename a parameter in ActiveAdmin just like I can do with the name of the class, but I haven't found an easy way to do that.
Let's suppose the following model:
Employee
name:string
role:string
I want that ActiveAdmin shows the "role" parameter as "Cargo" ("role" in brazilian portuguese) throughout all administrative panel.
I'm currently using the following workaround:
ActiveAdmin.register Employee, as: "empregado" do
permit_params :name, :role
# Rename the desired parameter in /admin/empregados
index do
column "Nome", :name
column "Cargo", :role
actions
end
# Rename the desired parameter in /admin/empregados/new
form do |f|
inputs do
input :name, label: "Nome"
input :role, label: "Cargo"
end
actions
end
# Rename the desired parameter in /admin/empregados/[:id]
show do
attributes_table do
row :id
row("Nome"){ empregado.name }
row("Cargo"){ empregado.role }
row("Criado em"){ empregado.created_at }
row("Atualizado em"){ empregado.updated_at }
end
end
end
This works, but it's quite manual and I don't think this is the "Railsistic way" to do things. Also, there's some places where the model wasn't renamed, like the "filters" for the search:
I would like to find an easy way to rename this column / parameter throughout all administrative panel without need to replicate code. There's a way to do that?
Upvotes: 2
Views: 2363
Reputation: 9226
ActiveAdmin uses ActiveRecord's translations when displaying anything related to a model, so in your case you could just add something like this to your es.yml file:
es:
activerecord:
models:
employee:
one: Empregado
attributes:
employee:
name: Nome
role: Cargo
created_at: Criado em
updated_at: Atualizado em
Upvotes: 4