Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

2nd level namespace routing

#1216

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)
      else
        .......
      end
    end

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

changed to

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

Reported by Joshua Tew · October 15th, 2008 @ 12:07 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Tom Stuart
    Tom Stuart

    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|
        # ...
      end
    end
    
    

    October 15th, 2008 @ 12:13 PM

  2. Joshua Tew
    Joshua Tew

    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
      end
    end
    

    and

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

    Thank you so much!! : )

    October 15th, 2008 @ 01:02 PM

  3. Pratik
    Pratik
    • State changed from new to invalid

    October 15th, 2008 @ 01:51 PM

  4. Andrea Campi
    Andrea Campi
    • Tag changed from 2, level, namespace to 2-3-stable, level, namespace
    • Importance changed from to

    October 16th, 2010 @ 11:44 PM