Routing inside a module

0 views
Skip to first unread message

Nicholas Wieland

unread,
Nov 6, 2008, 4:29:18 AM11/6/08
to me...@googlegroups.com
Hi, I would like a bunch of controllers handling something like an
administration interface, hidden inside a directory (just to have
controllers with the same name on controllers/ but that do all the
editing stuff).
I tried:

merb-gen controller '/admin/articles'

and it worked as I expected, creating a module Admin with a class
Articles inside.
It's all evening I'm trying to route my requests to go in that
Articles class and call the index action, and damn, I've got no clue.

At this point I have something like

match( "/:module/:controller/:action/:id" ).to( :controller =>
":module/:controller" )

I also tried hardcoding everything, like match( "/admin/blabla" ) but
nothing.

Can someone explain me how does this work ? ...

Should I use a part, a slice ?

Sorry, newbie here.
I'm having a lot of fun with Merb, thanks a lot guys.

ngw

Matthijs Langenberg

unread,
Nov 6, 2008, 4:40:05 AM11/6/08
to me...@googlegroups.com
I use:
    r.match('/admin').to(:controller => 'admin/sites')

and
  
  r.namespace :admin do |admin|
    admin.resources :administrators
    admin.resources :writers
    
    admin.resources :sites do |site|
      site.resources :writerships
      site.resources :templates
      site.resources :pages
    end
  end

Does this help you a bit?

Per Melin

unread,
Nov 6, 2008, 12:59:43 PM11/6/08
to me...@googlegroups.com
> At this point I have something like
>
> match( "/:module/:controller/:action/:id" ).to( :controller =>
> ":module/:controller" )

That should work, but you'd always have to use the *full* url,
including action and id.

This makes action and id optional:
match("/:module/:controller(/:action(/:id))").to(:controller =>
":module/:controller")

But in your case I would do this:
namespace(:admin) do
default_routes
end
default_routes

It works, though I'm not sure if it is the officially recommended way.
I haven't seen any router specs that use default_routes inside
namespaces.

Watch out for the order you specify your routes in. If you have a
default_routes first it will catch almost everything and other matches
or namespaces you set up after that will be useless.

Reply all
Reply to author
Forward
0 new messages