2016-02-28 43 views
0

我在Rails测试项目中使用Rails 4.2.5和最新版本的ActiveAdmin。我想重新命名ActiveAdmin中的一个参数,就像我可以使用the name of the class一样,但我还没有找到一个简单的方法来做到这一点。重命名ActiveAdmin中的参数/字段

让我们假设以下模型:

Employee 
    name:string 
    role:string 

我想这ActiveAdmin显示了“角色”参数设置为“货物”(“角色”在巴西葡萄牙语)在所有管理面板。

我目前使用以下解决方法:

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 

这工作,但它是相当手册,我不认为这是“Railsistic方式”做事。此外,还有一些地方的模型并没有改名,如“过滤器”的搜索: enter image description here

我想找到一个简单的方法,无需复制此列/参数在所有管理面板重命名码。有办法做到这一点?显示模型相关的东西的时候,所以你的情况,你可以只添加这样的事情你es.yml文件

回答

1

ActiveAdmin使用的ActiveRecord的翻译:

es: 
    activerecord: 
    models: 
     employee: 
     one: Empregado 
    attributes: 
     employee: 
     name: Nome 
     role: Cargo 
     created_at: Criado em 
     updated_at: Atualizado em 
+0

谢谢你,这个工作! – Paladini