5

I've been searching for a while now, but I can't seem to figure out if this is even possible. What I need is one controller for two different paths.

What I have is one model, with two types: own and compatitive.

So what I want is two paths like this, going both to one controller:

example.com/hotels

example.com/compatitives

These have to be resources, and there is going to be a lot of nesting in these routes. So I don't want to create a resource mapping for both of them.

I've already tried this:

resources :hotels, :compatitives, :controller => :hotels do

  resources :rooms do
    collection do
      match "/search", :action => :search
    end
  end

  collection do
    match "/search"
    match "/results/:type/:id(/:page)", :action => :results
  end

end

resources :prices do
  collection do
    match "/check"
  end
end

But the controller is not hotels_controller for both.

Is this even possible?

Thanks!

Tim Baas
  • 6,035
  • 5
  • 45
  • 72
  • 1
    What are "compatitives"? Also, please remove your edit from your question, and post it as an answer so you can accept it and "close" this question. It is completely acceptable to answer your own questions on Stack Overflow, but you do have to post the answer, not just amend the question to include the answer. – user229044 Jul 29 '11 at 12:51
  • Hehe, just after this post I found it had to be competitors.. I'm Dutch so not really familiar with the right spelling.. I've answered the question, thanks for pointing it out.. – Tim Baas Jul 29 '11 at 13:49

1 Answers1

1

Got it to work with this solution:

def add_hotel_collection
  resources :rooms do
    collection do
      match "/search", :action => :search
    end
  end
  collection do
    match "/search", :action => :search
    match "/results/:type/:id(/:page)", :action => :results
  end
end

resources :hotels do
  add_hotel_collection
end

resources :compatitives, :controller => :hotels do
  add_hotel_collection
end
Tim Baas
  • 6,035
  • 5
  • 45
  • 72