On Wednesday, May 18, 2011 8:47:44 AM UTC-6, John W wrote:
>
> Hello all 
>
> As I adopt REST more and more, my app has grown to have a lot of 
> nested routes - only nested one level deep - that are starting to get 
> a bit cumbersome to manage.  e.g. 
>
> resources :products do 
>   resource :promotion 
>   resource :discount 
>   # etc 
> end 
>
> each nested resource has it's own controller.  I'd like to group to 
> controllers so I used the :module option on each nested resource and 
> created a namespaced controller. e.g. 
>
> resources :products do 
>   resource :discount, :module => :product 
> end 
>
> This works fine, and the controller happily lives under controllers/ 
> product/discounts_controller.rb 
>
> However, a few of the libraries and gems I use don't cope so well with 
> namespaces, especially when the associated model isn't also 
> namespaced.  To get around this, I've added 'app/controllers/products' 
> as a load path in environment.rb and I've also added that path to the 
> view paths for relevant (nested) controllers. 
>

Any chance you'd be willing to list some of the gems that aren't working 
with your setup? It might be in yours and everyones best interest to try to 
fix get the gems themselves fixed so they can properly work with nested 
controllers and nested models.
 

>
> This has worked great so far and I my tests are passing.  I was just 
> wondering if anyone would caution against this approach?  I'm 
> generally quite cautious about changing defaults and expected 
> conventions! 
>
>
If it *is* working for you (your tests are passing after all) then I'd just 
go with your current solution (modifying the load path, etc) until the gems 
you depend on can be fixed. Those who better know rails internals may wish 
to comment, however, on future problems you may or may not have.

Either way, I'd treat your current solution as a temporary fix and try to 
fix the gems you rely on (most gem authors would welcome a 
patch/pull-request if it's clean and includes tests). I may be biased though 
since I was once frustrated by issues that arose from using nested models 
and controllers waaaay back in the rails 2 days.... I just think nesting 
ought to work and be supported/correctly-implemented across the rails 
landscape. My $0.02

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to