0

我正在尝试将 Mobility gem 与 Rails Admin 一起使用。我可以通过 Rails Admin 界面编辑字段(如 Ngo 模型的 Impact_description),它正确地更改了翻译表:

如果更改了影响描述,则在 Rails 控制台上进行测试

但问题是,Rails 管理界面没有显示正确的翻译(它显示在 pt-BR,即使应用程序是英文的):

在此处输入图像描述

有没有人成功地将 Rails Admin 与 Mobility gem 集成?感谢关注

编辑:在我的rails_admin.rb(初始化程序)中,我有所有操作的常规配置(仅更改新的):

config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new do
      except [RewardRule, SuggestedFeed]
    end
    export
    import
    bulk_delete
    show
    edit
    # delete
    clone
    show_in_app

    ## With an audit adapter, you can add:
    # history_index
    # history_show
  end

对于 Ngo 模型,我没有任何自定义配置,只是它包含在 Rails Admin 模型中:

# rails_admin.rb
config.included_models = [..., Ngo, ...]
4

1 回答 1

1

因此,在对 Rails Admin api 进行了一些研究后,我能够做到这一点。例如,为了在 show 动作中处理 Ngo 模型,我做了:

config.model Ngo do
  show do
    fields do
      formatted_value{ bindings[:object].send(method_name) } # this calls the mobility method instead of getting the plain attribute, so it will translate on the admin.
    end
  end
end

在这种情况下,所有字段都将调用原始方法名称,而不是普通属性。因此,例如,在我的情况下,它将调用ngo.impact_description,它将翻译字段,而不是读取ngo[:impact_description]将始终使用默认语言的普通属性。

于 2021-09-13T17:05:09.593 回答