-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Navigation
You can include/exclude models totally. They won't appear in RailsAdmin at all.
Blacklist Approach
config.excluded_models << "ClassName"
Whitelist Approach
By default, RailsAdmin automatically discovers all the models in the system and adds them to its list of models to
be accessible through RailsAdmin. The excluded_models
configuration above permits the blacklisting of individual model classes.
If you prefer a whitelist approach, then you can use the included_models
configuration option instead:
config.included_models = ["Class1", "Class2", "Class3"]
Only the models explicitly listed will be put under RailsAdmin access, and the auto-discovery of models is skipped.
The blacklist is effective on top of that, still, so that if you also have:
config.excluded_models = ["Class1"]
then only Class2
and Class3
would be made available to RailsAdmin.
The whitelist approach may be useful if RailsAdmin is used only for a part of the application and you want to make sure that new models are not automatically added to RailsAdmin, e.g. because of security concerns.
Once done with the choice of model, you can customize the way they appear in the navigation.
Setting the model's label
config.model Team do
label "List of teams"
end
This label will be used anywhere the model name is shown, e.g. on the navigation tabs, Dashboard page, list pages, etc.
Hiding a model
You can hide a model from the top navigation by marking its visible
option
as false:
By passing the value as an argument:
config.model Team do
visible false
end
Or by passing a block that will be lazy evaluated each time the option is read:
config.model Team do
visible { false }
end
These two examples also work as a generic example of how most of the
configuration options function within RailsAdmin. You can pass a value as an
argument option_name value
, or you can pass in a block which will be
evaluated each time the option is read. Notable is that boolean options' reader
accessors will be appended with ? whereas the writers will not be. That is, if
you want to get the Team model's visibility, you use
RailsAdmin.config(Team).visible?
.
Create a navigation_label in navigation
# Given there are the following models: League, Team and Division
config.model Team do
parent League
end
config.model Division do
parent League
end
Obtained navigation:
Dashboard
...
League # (non-clickable)
League
Division
Team
...
You probably want to change the name of the navigation_label. This can be easily achieved with the 'navigation_label' method of the parent model.
Added to previous example:
config.model League do
navigation_label 'League related'
end
Obtained navigation:
Dashboard
...
League related # (non-clickable)
League
Division
Team
...
Change models order in navigation
By default, they are ordered by alphabetical order. If you need to override this, specify a weight attribute. Default is 0. Lower values will bubble items to the top, higher values will move them to the bottom. Items with same weight will still be ordered by alphabetical order. The mechanism is fully compatible with navigation labels. Items will be ordered within their own menu subset. (but parent will always be first inside his submenu).
Example:
config.model League do
navigation_label 'League related'
weight -1
end
The 'League related' navigation label will move to the topmost position.
Method for instances label
object_label_method