Radu Cugut
Radu Cugut

Reputation: 1673

Rails 3 routes for nested controllers and sub-folders

I need some help with routes for nested controllers. I can't figure out from the Rails guide docs by myself.
I have the following controllers in a rails 3.2 app:

/app/controllers/organizations_controller.rb (class OrganizationsController)
/app/controllers/organization/events_controller.rb (class Organization::EventsController)

then, in routes.rb

resources :organizations, path: 'org' do
  resources :events
    member do
      get 'confirm'
    end
  end
end

running rake routes shows (only the relevant part for my issue):

 organization_event  GET  /org/:organization_id/events/:id(.:format)  events#show

The URL is ok, the route name is also ok, but the mapping to the "controller/action" is not right. Not as I want it to be. It should be organization/events#show.

What am I missing? How can I point this route to the correct controller. I chose to put the events_controller in the organization folder, because I already have another events_controller placed in the root of the controllers folder, and they have different purposes.
Thank you

Upvotes: 5

Views: 6449

Answers (1)

shime
shime

Reputation: 9008

namespace :organization do
   resources :events 
      member do
        get "confirm"
      end
   end
end

More info here.

EDIT

Sorry, didn't understand you correctly.

resources :organizations, path: 'org' do
  resources :events, :module => "organization"
    member do
      get 'confirm'
    end
  end
end

Does that fit your needs?

Upvotes: 6

Related Questions