This project is archived and is in readonly mode.

#1216 ✓invalid
Joshua Tew

2nd level namespace routing

Reported by Joshua Tew | October 15th, 2008 @ 12:07 PM | in 2.x

my project requires the use of 2 level namespace routing

created the routing config in routes.rb

map.namespace(:school_admin, :namespace => :staff) do |school_admin| school_admin.resources :programmes end

in a view a link was created with

link_to 'Show', school_admin_programme_path(programme)

the link maps to address [webroot]/school_admin/programme/[some id]

now rails throw an error

uninitialized constant StaffschoolAdmin

my guess is that there should have been a / between staff and schoolAdmin

I managed to get the system working by hacking route_set.rb to add a "/" to the path generation process when :namespace option is supplied, that is...

def namespace(name, options = {}, &block)

      if options[:namespace]
        with_options(........, :namespace => "#{options.delete(:namespace)}/#{name}/" }.merge(options), &block)

so instead of :namespace => "#{options.delete(:namespace)}#{name}/"

changed to

:namespace => "#{options.delete(:namespace)}/#{name}/"

Comments and changes to this ticket

  • Tom Stuart

    Tom Stuart October 15th, 2008 @ 12:13 PM

    This is wrong. The :namespace option is for internal use by the namespace method, to support nested namespaces -- if you insist on setting it manually you must comply with its existing semantics (i.e. it ends with a slash).

    If you want to nest namespaces, go right ahead:

    map.namespace(:school_admin) do |school_admin|
      school_admin.namespace(:staff) do |staff|
        # ...
  • Joshua Tew

    Joshua Tew October 15th, 2008 @ 01:02 PM

    Oops my sincere apologies for my ignorance of the nested namespace

    Thanks for the info, managed to get what I want by

    map.namespace(:staff) do |staff|
      staff.namespace(:school_admin) do |school_admin|
        school_admin.resources :programmes


    <% form_for([:staff,:school_admin, @programme]) do |f| %>

    Thank you so much!! : )

  • Pratik

    Pratik October 15th, 2008 @ 01:51 PM

    • State changed from “new” to “invalid”
  • Andrea Campi

    Andrea Campi October 16th, 2010 @ 11:44 PM

    • Tag changed from 2, level, namespace to 2-3-stable, level, namespace
    • Importance changed from “” to “”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket