Reputation: 31
I'm trying to use the Mobility gem with Rails Admin. I am able to edit fields through the Rails Admin interface (like the impact_description of a Ngo model) and it correctly changes the translation tables:
But the problem is, the Rails Admin interface does not show the correct translation (it is showing in pt-BR, even when the app is in english):
Has anyone sucessfully integrated Rails Admin with the Mobility gem? Thanks for the attention
EDIT:
In my rails_admin.rb
(initializer) I have the regular configurations for all actions (only changing new):
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
And for the Ngo model I don't have any custom configuration, only that it is included on the Rails Admin models:
# rails_admin.rb
config.included_models = [..., Ngo, ...]
Upvotes: 0
Views: 357
Reputation: 31
So I was able to do it after some research in the Rails Admin api. For this to work on the Ngo model in the show action, for example, I did:
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
In this case, all the fields will be calling the original method name, instead of the plain attribute. So for example, in my case, it will be calling ngo.impact_description
, which will get the field translated, instead of reading the plain attribute ngo[:impact_description]
, which will always be in the default language.
Upvotes: 1