Routing to controller inside module


#1

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 T. - 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


#2

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

#3

Am Montag, den 16.01.2006, 17:46 +0000 schrieb James A.:

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 :wink:

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 T.

http://blog.inlet-media.de

Norman T. - 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


#4

Am Montag, den 16.01.2006, 17:46 +0000 schrieb James A.:

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 :wink:

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 T.

http://blog.inlet-media.de

Norman T. - 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