# Module for site "admin"?

**URL:** <https://www.ruby-forum.com/t/module-for-site-admin/72246>\
**Category:** Rails\
**Created:** [October 16, 2006, 12:31am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246 "2006-10-16T00:31:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 16, 2006, 12:31am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246/1 "2006-10-16T00:31:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 17, 2006, 1:04am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246/2 "2006-10-17T01:04:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 17, 2006, 1:29am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246/3 "2006-10-17T01:29:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 17, 2006, 2:06am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246/4 "2006-10-17T02:06:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 17, 2006, 5:34am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246/5 "2006-10-17T05:34:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 17, 2006, 2:23am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246/6 "2006-10-17T02:23:10Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 17, 2006, 5:38am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246/7 "2006-10-17T05:38:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [October 17, 2006, 8:54am UTC](https://www.ruby-forum.com/t/module-for-site-admin/72246/8 "2006-10-17T08:54:10Z")

</div>

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.
