Forum: Ruby on Rails routing to controller inside module

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.
E8a1ea4c8e4d8fb7aaaf1b63d4a83f0a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-01-16 18:13
(Received via mailing list)
Hey,

am i to stupid to find the information about how to route to a
controller in a module? Maybe module support has gone!

The controller is under:
app/controllers/admin/my_controller.rb

The my_controller.rb file looks like this:
module Admin
  class MyController
    def index
      render :text => 'Hello!'
    end
  end
end

How does a route to all controllers under module Admin look like?
map.connect 'admin/:controller/:action/:id', :module => 'admin'

This one gives me a NameError 'uninitialized constant
DepartmentController'

I tested following with the same result:
map.connect 'admin/my_controller/:action/:id', :controller =>
'admin/my_controller'

Are controllers within modules still supported?

Ciao,
Norman
--
Norman Timmler - inlet media e.K.

Phone: +49 (0)40 / 43 25 10 81
Fax:   +49 (0)40 / 43 25 10 82

Holländische Reihe 31
22765 Hamburg

http://www.inlet-media.de
05d703f649ef1d07e78d7b479fb4c4ac?d=identicon&s=25 James Adam (Guest)
on 2006-01-16 18:46
(Received via mailing list)
You probably want something more like this, in
/app/controllers/admin/my_controller.rb:

class Admin::MyController < ApplicationController
   ........
end

Rails will create the Admin module using its own dark magicks. You
shouldn't need to touch the default controller route either.

- james
E8a1ea4c8e4d8fb7aaaf1b63d4a83f0a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-01-17 02:01
(Received via mailing list)
Am Montag, den 16.01.2006, 17:46 +0000 schrieb James Adam:
> You probably want something more like this, in
> /app/controllers/admin/my_controller.rb:
>
> class Admin::MyController < ApplicationController
>    ........
> end
>
> Rails will create the Admin module using its own dark magicks. You
> shouldn't need to touch the default controller route either.

Sorry, but i figured out a typing error caused the problem ;)

By the way,

class Admin:Mycontroller

and

module Admin
  class MyController

are the same, with the only difference, that the first one only works if
the module has been declared before.
--
Norman Timmler

http://blog.inlet-media.de
--
Norman Timmler - inlet media e.K.

Phone: +49 (0)40 / 43 25 10 81
Fax:   +49 (0)40 / 43 25 10 82

Holländische Reihe 31
22765 Hamburg

http://www.inlet-media.de
E8a1ea4c8e4d8fb7aaaf1b63d4a83f0a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-01-17 02:01
(Received via mailing list)
Am Montag, den 16.01.2006, 17:46 +0000 schrieb James Adam:
> You probably want something more like this, in
> /app/controllers/admin/my_controller.rb:
>
> class Admin::MyController < ApplicationController
>    ........
> end
>
> Rails will create the Admin module using its own dark magicks. You
> shouldn't need to touch the default controller route either.

Sorry, but i figured out a typing error caused the problem ;)

By the way,

class Admin:Mycontroller

and

module Admin
  class MyController

are the same, with the only difference, that the first one only works if
the module has been declared before.
--
Norman Timmler

http://blog.inlet-media.de
--
Norman Timmler - inlet media e.K.

Phone: +49 (0)40 / 43 25 10 81
Fax:   +49 (0)40 / 43 25 10 82

Holländische Reihe 31
22765 Hamburg

http://www.inlet-media.de
This topic is locked and can not be replied to.