Inheriting from AdminController intstead from ApplicationController

Hi

I would like to do the following:

I have created an admin namespace and the required folders app/admin
views/admin etc. And then I wanted all controllers under app/admin to
inherit from a controller named AdminController which resists under
app/admin/admin.rb instead of inhereting from ApplicationController,
so I could better separate between admin and public section. The
AdminController looks like this:

module Admin
class AdminController < ActionController::Base
include AuthenticatedSystem
helper :all
protect_from_forgery
layout ‘admin/layouts/admin’
end
end

For testing the new namespace I created a GroupsController which looks
like this:

require ‘admin/admin’
module Admin
class GroupsController < AdminController
def index
@groups = Group.find(:all)
end
end
end

But every time I call the GroupsController I’m getting the following
error:

uninitialized constant Admin::AdminController

Can anybody tell me what I’m doing wrong?

Thanks
Mato

If AdminController is within admin/ I think your class name needs to
include the namespace, Admin::AdminController. I’ve been putting
together an ‘admin’ section myself by doing this and that’s how I’ve
been doing things.

Hope this helps, I’ll keep my eye on this post to see how things go.

Dave K.

Hi

I agree with Dave. You Have to include Admin::AdminController. I think
this
should be the trick,else reply to this post again.

  • Rajesh

On Sat, Mar 29, 2008 at 9:22 PM, David K. [email protected] wrote:

On Mar 28, 1:29 pm, milic [email protected] wrote:

like this:
But every time I call the GroupsController I’m getting the following
error:

uninitialized constant Admin::AdminController

Can anybody tell me what I’m doing wrong?

Thanks
Mato


Happiness keeps u Sweet, Trials keep u Strong, Sorrow keeps u Human,

Failure Keeps u Humble, Success keeps u Glowing, But only God Keeps u

Going…

Keep Going…

Hi

Thanks for your purposes but the problem still exists. The behaviour
of the application has now changed. The first time I call a controller
within the admin namespace it works fine, but when I reload the page
the same error occurs again.

By the way, is it possible to configure rails to load the admin.rb
file automaticly every time a controller in the admin namespace is
called (like application.rb)?

Mato

Your controller rests under app/admin/admin.rb, which won’t be loaded
automatically by rails because it doesn’t have a _controller suffix. I
would
suggest renaming this file to Admin::ApplicationController for its class
and
application_controller.rb as its file name, that way it will be
automatically loaded and it will make sense what that controller’s
supposed
to be doing.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

If you’re really fussed with that, then define an index action in there
that
redirects people to where they should be. Not many people will be trying
to
go to admin/application unless they know it’s there.

On Sun, Mar 30, 2008 at 9:56 AM, milic [email protected] wrote:

automatically by rails because it doesn’t have a _controller suffix. I
Feel free to add me to MSN and/or GTalk as this email.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

On Mar 29, 2008, at 6:22 PM, Ryan B. (Radar) wrote:

ApplicationController, so this one can’t be called from outside.

automatically loaded and it will make sense what that controller’s
supposed
to be doing.

I’m wondering whether you’re trying to swim upstream with the
inheritance approach inside a module. It seems you want to share some
behaviors among your administrative controllers. Would a mixin work as
well as direct inheritance here? E.g.:

module Admin
class AdminController < ApplicationController
include KewlAdminMethods

end
end

Any chance that would solve your problem?

This solution works, but with one disadvantage. Now when I call
http://mydomain.com/admin/application, the
Admin::ApplicationController is called which shouldn’t be possible.
That’s why I originally wanted to build something like the normal
ApplicationController, so this one can’t be called from outside.

On 30 Mrz., 00:03, “Ryan B. (Radar)” [email protected]

Hi

I think your right Ryan, not many people will try to go to admin/
applicaton.

s.ross: This would cause the same problems, because this file would
also not be loaded properly.

Thank you guys for the help.

Mato

Admin is not a module, it’s a namespace, Admin::ApplicationController.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

On Mar 30, 2008, at 3:47 AM, Ryan B. (Radar) wrote:

Admin is not a module, it’s a namespace, Admin::ApplicationController.


Ryan B.
http://www.frozenplague.net

While the intent may be to create a namespace, it very much is a
module. Here is the original code:

module Admin
class AdminController < ActionController::Base
include AuthenticatedSystem
helper :all
protect_from_forgery
layout ‘admin/layouts/admin’
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs