Module for site "admin"?

I’m working on building an administration (cms) system for websites that
I manage. I’m trying my best to stick to the RESTful concepts, so right
now I have my controllers structured like this:

-app
–controllers
----news_stories_controller.rb <-- Manage news stories (administration
system)
----news_controller.rb <-- View news stories (public side)
----calendar_events_controller.rb <-- Manage calendar events
(administration system)
----calendar_controller.rb <-- View calendar events (public side)

Note that in my routes.rb I prefix all the “administration system”
controllers with ‘/admin’.

Would it make more sense to re-factor this to use modules (namespaces)
so it would be structured like this?

-app
–controllers
----admin
------news.rb <-- Manage news stories
------calendar.rb <-- Manage calendar events
----news.rb <-- View news stories
----calendar.rb <-- View calendar events

I’ve heard a lot of bad things about modules, but it seems like most of
the problems come down to naming conflicts when you’re dealing with
namespaced models. I much prefer the module approach because it keeps
everything separated and organized…what do you guys think?

Andrew

There is an excellent discusison on namespaces in AWDwR book. You will
basically have two different directories containing the same class
name but the namespace will be distinguised by using the :: operator.

Andrew H. wrote:

I’ve heard a lot of bad things about modules, but it seems like most of
the problems come down to naming conflicts when you’re dealing with
namespaced models.

It’s all FUD. I haven’t experienced any problems using controller
modules. I’m not sure what “namespaced models” are.

Joe

Joe R. MUDCRAP-CE wrote:

Andrew H. wrote:

I’ve heard a lot of bad things about modules, but it seems like most of
the problems come down to naming conflicts when you’re dealing with
namespaced models.

It’s all FUD. I haven’t experienced any problems using controller
modules. I’m not sure what “namespaced models” are.

Joe

It is what it is. In my experience, a number of plugins, especially but
by no means only ones involved in authentication and authorization, have
problems with namespaced controllers. One of my early apps was built
with controller modules for Admin::* operations, but the time spent
dealing with the problems eventually became enough of an annoyance that
I got rid of the hierarchy and flattened out my controllerspace. Getting
work done is more imporant to me than a fixation on Code Esthetics, and
if I really had that many admin controllers I wanted to segregate, I
suppose I could prefix them and their corresponding helpers and view
directories with “admin_”.

YMMV. :slight_smile:

Joe R. MUDCRAP-CE wrote:

Andrew H. wrote:

I’ve heard a lot of bad things about modules, but it seems like most of
the problems come down to naming conflicts when you’re dealing with
namespaced models.

It’s all FUD. I haven’t experienced any problems using controller
modules. I’m not sure what “namespaced models” are.

Joe

I actually did some playing with namespaced controllers (modules) last
night and ended up running into some problems after-all…so I think I’m
going to stay away from the whole concept. I prefer REST over RPC, and
there are some big compatibility problems with the simply_restful
support in edge rails and namespaces. I figure I’ll just stick with
using before_filters on specific actions as opposed to separating
everything out.

Andrew

Steve K. wrote:

It is what it is. In my experience, a number of plugins, especially but
by no means only ones involved in authentication and authorization, have
problems with namespaced controllers. One of my early apps was built
with controller modules for Admin::* operations, but the time spent
dealing with the problems eventually became enough of an annoyance that
I got rid of the hierarchy and flattened out my controllerspace. Getting
work done is more imporant to me than a fixation on Code Esthetics, and
if I really had that many admin controllers I wanted to segregate, I
suppose I could prefix them and their corresponding helpers and view
directories with “admin_”.

YMMV. :slight_smile:

Hmm, yeah, I guess if I had some plugins I couldn’t live without (which
I don’t – I’ve checked out all the member/user plugins and didn’t like
any of them). But then I’d say the plugin author is to blame for not
working with namespaced controllers, and maybe I’d even also try to get
it to work with namespaced controllers. I just looove how namespaced
controllers keep individual files simple.

Joe

Andrew H. wrote:

Joe R. MUDCRAP-CE wrote:

Andrew H. wrote:

I’ve heard a lot of bad things about modules, but it seems like most of
the problems come down to naming conflicts when you’re dealing with
namespaced models.

It’s all FUD. I haven’t experienced any problems using controller
modules. I’m not sure what “namespaced models” are.

Joe

I actually did some playing with namespaced controllers (modules) last
night and ended up running into some problems after-all…so I think I’m
going to stay away from the whole concept. I prefer REST over RPC, and
there are some big compatibility problems with the simply_restful
support in edge rails and namespaces. I figure I’ll just stick with
using before_filters on specific actions as opposed to separating
everything out.

Andrew

I’m curious – what problems specifically? I haven’t really messed
around with web services yet. If there are conflicts with controller
namespaces, I’m sure Rails core would like to hear about them (i.e.
tickets).

Joe

Joe R. MUDCRAP-CE wrote:

Andrew H. wrote:

Joe R. MUDCRAP-CE wrote:

Andrew H. wrote:

I’ve heard a lot of bad things about modules, but it seems like most of
the problems come down to naming conflicts when you’re dealing with
namespaced models.

It’s all FUD. I haven’t experienced any problems using controller
modules. I’m not sure what “namespaced models” are.

Joe

I actually did some playing with namespaced controllers (modules) last
night and ended up running into some problems after-all…so I think I’m
going to stay away from the whole concept. I prefer REST over RPC, and
there are some big compatibility problems with the simply_restful
support in edge rails and namespaces. I figure I’ll just stick with
using before_filters on specific actions as opposed to separating
everything out.

Andrew

I’m curious – what problems specifically? I haven’t really messed
around with web services yet. If there are conflicts with controller
namespaces, I’m sure Rails core would like to hear about them (i.e.
tickets).

Joe

The main thing that was annoying me is that the named routes that
simply_restful generates were acting strange…I’ll have to test it out
again tomorrow to replicate the problem - I don’t recall exactly what
the error was. It may have been something I did wrong, but all I did
was move my controllers into an admin::* namespace and set the resource
path_prefix to ‘/admin’, which seemed like the logical thing to do.

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