Forum: Ruby on Rails Routing and namespace

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Anton A. (Guest)
on 2007-02-19 18:03
(Received via mailing list)
I'm trying to set up and 'admin' interface for each of my models.

I have a controller for each of them under 'app/controllers/admin/'
                book_controller.rb
                page_controller.rb
and so on.

So as not to get in the way of normal use I'm 'forcing' a prefix in the
routing/url with lines in routes.rb like

 map.connect '/admin/page/:page/:action',
              :controller   => 'admin/page_controller',
              :action       => 'show',
              :requirements => { :page => page_name_requirement }


when I experiment with app.url_for() in the console I get the results I
expect.

But when I fire up the server and try to go to

   http://localhost.:3000/admin/page/ChapterOne

I get

 NameError in Admin/web controllerController#list

uninitialized constant Admin::WebControllerController


Two questions:

Should my controller read:

    class Admin::WebController < ApplicationController

which was how it was generated

and/or should the routing be fudged in some way.

Remember, this is not the 'real' application.
The real application comes out at

       http://localhost.:3000/TheStoryofLitchfileld/ChapterOne

and the routing for that is lower down in the routes.rb
--
"Quality refers to the extent to which processes, products, services,
and
relationships are free from defects, constraints and items which do not
add
value."
   - Dr. Mildred G Pryor, 1995
Paul B. (Guest)
on 2007-02-19 19:17
(Received via mailing list)
If you have a controller in app/controllers/admin/book_controller.rb
defined like this:

class Admin::BookController < ApplicationController

Then the default route to the controller will be /admin/book.  There
is no need to add anything to routes.rb, it will "just work".
Anton A. (Guest)
on 2007-02-19 23:40
(Received via mailing list)
Paul B. said the following on 02/19/2007 12:16 PM:
> If you have a controller in app/controllers/admin/book_controller.rb
> defined like this:
>
> class Admin::BookController < ApplicationController
>
> Then the default route to the controller will be /admin/book.  There
> is no need to add anything to routes.rb, it will "just work".

Ah.
I see, that picks up on the default.

Now what about my custom application route, then.
It is supposed to be

       http://localhost:3000/TheStoryofLitchfileld/ChapterOne


aka     ":book/:chapter" and that goes to the book_chapter_controller.rb

There is path before it to indicate the namespace or the controller.

--
Always do your best. What you plant now, you will harvest later.
   - Og Mandino
This topic is locked and can not be replied to.