views:

197

answers:

1

So I have an existing rails app that I've been asked to retrofit to support a flex client. Since I don't really want to muck around with the existing controllers and routes, I thought the best way to accomplish this would be to create a subdirectory in app/controllers called flex and put in some additional controllers in there to handle the flex specific requests.

So basically, instead of a request to /sessions/ [method = POST] I'd want to route /flex/sessions/ [method = POST] to go to my sessions_controller in the flex sub directory. I can get it to go to the correct controller, but it's looking for the idnex method (so it looks like it's treating my request as a GET request even though the log says its a POST request.

Any thoughts on how to add this controller to my routes file to handle the HTTP verbs?

Right now the only addition to my routes.rb has been

map.connect 'flex/sessions/:action', :controller => 'flex/sessions'

Thanks in advance for any help.

s.park

+1  A: 

Try using namespaces.

map.namespace(:flex) do |flex|
  flex.connect 'sessions/:action', :controller => 'sessions'
  #or, ya know, use more restful routes now that you're in /flex/
  flex.resources :sessions
end
Matchu
Thanks. I just tried that, but still not luck.The POST request to http://localhost:3000/flex/sessions keeps showing up in my logs as Processing SessionsController#index (for 127.0.0.1 at 2009-06-24 16:18:08) [POST]so I can see that it's a POST request, but it gets routed to the SessionsController's index method and it doesn't look like the right controller either. the relevant part of my rake routes output isPOST /flex/sessions {:controller=>"flex/sessions", :action=>"create"}any thoughts on how to better debug routes?
sparky
Are you using the resources line or that connect line? Use the resources helper if you aren't already.
Matchu
Getting rid of the first line flex.connect 'sessions/:action', :controller => 'sessions'seems to have worked for me.
sparky
Alright, cool :) And welcome to StackOverflow! When a posted answer helps solve your problem, you usually click the little check mark on it so everyone knows the question is already taken care of ^_^
Matchu