Reputation: 394
How to change navigation label in rails_admin?
Here is app/models/admin.rb
:
module Admin
def self.table_name_prefix
'admin_'
end
end
and app/models/admin/seo.rb
:
class Admin::Seo < ActiveRecord::Base
end
I'd like to change the Rails Admin navigation label of the Admin::Sea
model to "Admin".
I tried the following in config/locales/ru.yml
:
activerecord:
models:
admin:
one: test
other: test1
admin/seo:
one: SEO - данные
other: SEO - данные
Also I tried in config/initializers/rails_admin.rb
:
config.model Admin do
label 'test1'
label_plural 'test1'
navigation_label 'test1'
end
Upvotes: 0
Views: 921
Reputation: 2309
In my project it works like this
activerecord:
models:
admin/seo:
one: SEO - данные
other: SEO - данные
And you would not need your initializer.
Also it should be ru.yml
not en.yml
because it translation for Russian language so it must be used only for Russian locale.
UPDATE 1
I found some answer but I am not sure it is the best one (but it works)
class Admin::Seo < ActiveRecord::Base
rails_admin do
navigation_label I18n.t('your.translation.path.here')
end
end
You can also put this code inside initializer not model (it is up to you).
You can see here how rails_admin
generates this sidebar.
So each model should have navigation_label
or it would be default t('admin.misc.navigation')
.
UPDATE 2
You can set navigation_label
for all the models during initialization like this
# config/environment.rb
...
RailsAdmin::Config.models.each do |model|
if model.abstract_model.model_name.starts_with? 'Admin::'
model.navigation_label I18n.t('your.translation.path.here')
end
end
This will split all models with Admin
namespace and other models into two separate menus in sidebar.
The code is placed in environment.rb
because translations are not available in initializers/*.rb
.
Upvotes: 1