0

I have several namespaced routes in an app. Here's a sample

namespace "battles" do
  resources :teams do
    resources :comments, :module => "comments", :controller=>'comments'
  end
end

My problem is that all my resources with comments route to the comments/comments controller, but because :teams is in the battles namespace, then the app tries to route to battles/comments/comments

Is there a way to specify that the nested comment resource should route to the comments/comments controller, not the battle/comments/comments controller.

John
  • 135
  • 2
  • 11
  • If you don't want comments to be in the namespace, then why don't you just move it out? Are your comments routes actually nested inside teams? (It doesn't look like it from your description). – Ylan S Aug 16 '12 at 20:52
  • Comments are all tied to a commentable (which in this case is teams). I need to know that I am commenting on a team vs something else (so all my commentables have nested comment routes). My comments controller has a find_commentable method that looks at the previous part of the URL to figure what type of model to load. – John Aug 16 '12 at 20:55

2 Answers2

0

Try

     scope :module => "battles" do  
        resources :teams do
         resources :comments, :module => "comments", :controller=>'comments'   
       end 
    end
Raghu
  • 2,543
  • 1
  • 19
  • 24
0

I gave up and just created a Battle::Comments controller. It results in code duplication so it's not ideal.

John
  • 135
  • 2
  • 11
  • You could also add this line to the end of your Comments controller: Battles::CommentsController = CommentsController Also not ideal, but better than code duplication. – charredUtensil Jul 13 '13 at 03:47