Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Additional navigation proposal #561

wants to merge 1 commit into from

In a couple of my projects, I used rails_admin as my application framework. It covers 80% of what I needed and I only had to implement a few home made controllers to handle the 20% left.

Note that to accomplish this I used the following technique: which allows to reuse the awesome Activo theme of Rails Admin for my whole application.

Now, I needed to insert some additional links to my home made controllers into the Rails Admin navigation.

Another use case would be if I wanted to have a permanent link always in the navigation: for instance, let's say I have a customer model, and I want to always see a link to "Add new customer" in my navigation (from every admin pages). I could use the feature as well.

This pull request is a first stab at it, which I think is not ideal:
1) I don't like the configuration syntax that much
2) It's missing tests and docs (to be fixed of course)

The syntax currently looks like this

RailsAdmin.config do |config|
    config.nav_before_models = {
        'foo' => {
            'label' => 'Foo',
            'url' => 'foo/foo',
        'bar' => {
            'label' => 'Bar',
            'url' => 'bar/bar'
    config.nav_after_models = {
        'stuff' => {
            'label' => 'More stuff',
            'url' => 'more/stuff'

Ideally, I wanted to use the RailsAdmin::Config::Navigation class, but it's being deprecated. The syntax could have looked like this:

RailsAdmin.config do |config|
    config.navigation.before_models do
        link :foo do
            label 'Foo'
            url 'foo/foo'
        link :bar do
            label 'Bar'
            url 'bar/bar'
    config.navigation.after_models do end
        link :stuff do
            label 'More stuff'
            url 'more/stuff'

What do you think? Any suggestion on what would be the best approach?


Also, like for the Custom footer pull request, another approach would be to create some partials that would be inserted into the navigation.


@jphpsf, @gunn: As with #560 I see customizing navigation (including top navigation) programmatically extremely important from view of extensions. This is a great discussion starter so lets map the requirements here before implementing more. I have couple of ideas which I'll list here later today (when I have bit more spare time.)


I would want to go with something partial based rather than just raw config based. There are far more things that people might want to customise than we can really anticipate.

One interesting approach to allowing lots of customisation is radiantcms' shards system. It would let us do something like: "help_links", :after => "navigation"

Where help_links is the name of a partial. As well as adding, you can also remove, replace or reorder partials. Perhaps we could even do something like: "copyright_notice", :text => "Acme | 2011"

So you are thinking about adding a configuration section to Rails Admin that could be called Page? And that could be used to configure/override various aspects of the user interface that are not directly related to Models. A short list of what could be customized:

  • header title/logo
  • header links/icons (dashboard and home currently)
  • footer text
  • sidebar navigation
  • breadcrumb

Does it need to use that syntax you are suggesting though? If it's all partial based, one could just replace the partial under app/ to override Rails Admin default and not have to worry about playing with the configuration?

e.g. using a _footer.html.haml (like _title.html.haml) instead of RailsAdmin::Config.footer or "copyright_notice", :text => "Acme | 2011"


It doesn't need to use that exact syntax, the idea is that we expose a simple data structure (could be as simple as arrays of arrays) that keeps track of what should be rendered.

The advantage over just overriding partials is that as well as just overriding, we could also insert before/after or reorder. This becomes is more important if we're thinking about a extension API which should allow multiple extensions to co-exist with one another.

Imagine, with this system instead of having an overrideable navigation partial with nav_before_models and nav_after_models areas on either side, we just declare our one navigation section and let people use it however they want.

The idea behind my second example is that in some cases (like for a footer as you point out), plain text is enough.

Some more areas for extension:

  • the icons for each row in the list view (show, edit, delete)
  • everywhere there are buttons - the top and bottom of every list edit and show page at least.

I've also run into the same issue - i want more ability to customize admin pages that may not be directly related to models. Also, being able to customize bits of the pages (the welcome note, the footer etc) with partials seems really good.

I'm forking the project and will try to follow the above suggested direction. if it works out, i'll send back a pull request.


@dunn Fair enough. In the case of the Navigation, partials might not even be needed.

The logic of building the list of links for navigation could be extracted from _navigation.html.haml partial, maybe a method getLinks on the Navigation object (well, the one that is actually being deprecated actually).

That getLinks method would build the list of link by merging the rails admin default links (such as dashboard) and the model links. It will also merge in user added links as well as extensions added links. The method could get all the links + their weight and then order them properly (If needed more flexibility in terms of position, maybe something more evolve than weight is needed). Also, that would be less logic in the view :)

Syntax wise, it could look like this (I am going back to a similar syntax as my original post's second example) for user defined links:

RailsAdmin.config do |config|
    config.navigation.userDefined do
        link :foo do
            label 'Foo'
            url 'foo/foo'
            weight 2
        link :bar do
            label 'Bar'
            url 'bar/bar'
            weight 3

From an extension perspective, Rails Admin could have hooks to add more links to the list of links (not sure yet how, I am not familiar with Rails Admin extensions)


I like it! This would be really handy for a project I'm working on. For what it's worth I'm in favor of a method based customization, rather than having a partial.

@jphpsf I like your last example. If you could set weights within the models as well that would offer complete control over the ordering. Something like this:

class League < ActiveRecord::Base
  rails_admin do
    navigation_weight 5

@kaapa what were your other ideas on this?

By the way, we talked a while ago about maybe changing the DSL to create simple data structures i.e. probably just arrays and hashes. There's a very simple library (one small file) that helps with that -


Which is the state of the implementation of partials for customizing the modules? This will be implemented for customizing most parts?

Symfony admin generetor works with partial. It's a really nice and easy way for customizing admin interfaces.

+1 for partials!


I'm 100% with @gunn idea of partial "hooks". Seems simple yet highly configurable!


Ok, so just checking: currently there's no way to change the links in the nav bar?


@dogweather "That can be achieved by coping _secondary_navigation.html.haml to your app's app/view/layouts/rails_admin/ and editing in the way you want."

As said by mshibuya here #1073


Have you guys seen deface? - - it was developed for Spree for pretty similar purposes


Is it possible to use Spree's deface gem with rails_admin? We are trying to override rails_admin's default layout (application.html.haml) but without any luck. Deface is unable to find the template, as there is no load path for rails_admin views.


Closing this, because this is too outdated and can't be merged in cleanly.
Another proposal will be welcomed!

@mshibuya mshibuya closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 16, 2011
  1. @jphpsf

    Additional navigation proposal

    jphpsf authored
This page is out of date. Refresh to see the latest.
9 app/views/rails_admin/main/_navigation.html.haml
@@ -7,6 +7,9 @@
%li{:class => ("active" if @page_type == "dashboard")}
= link_to(t(""), rails_admin_dashboard_path)
+ - RailsAdmin::Config.nav_before_model.each do |page,link|
+ %li{:class => ("active" if @page_type == page)}
+ %a{:href => "#{link['url']}"}= link['label']
- root_models.each do |model|
- children = [model] + { |m| m.parent.to_s == model.abstract_model.model.to_s }
- tab_titles = { |child| child.abstract_model.pretty_name.downcase }
@@ -18,4 +21,8 @@
- children.each_with_index do |child, index|
%li{:class => ("active" if @page_type == tab_titles[index])}
- = link_to(child.label.pluralize, rails_admin_list_path(:model_name => child.abstract_model.to_param))
+ = link_to(child.label.pluralize, rails_admin_list_path(:model_name => child.abstract_model.to_param))
+ - RailsAdmin::Config.nav_after_model.each do |page,link|
+ %li{:class => ("active" if @page_type == page)}
+ %a{:href => "#{link['url']}"}= link['label']
7 lib/rails_admin/config.rb
@@ -71,6 +71,11 @@ class << self
# to be used as a label for object records. This defaults to [:name, :title]
attr_accessor :label_methods
+ # TODO: document these options properly
+ # Allow to insert additional navigation links into the navigation sidebar
+ attr_accessor :nav_before_model
+ attr_accessor :nav_after_model
# Stores model configuration objects in a hash identified by model's class
# name.
@@ -278,4 +283,4 @@ def visible_models
# Set default values for configuration options on load
Something went wrong with that request. Please try again.