Reputation: 7068
I know this isn't RESTful, but for now, I'm trying to set up an api/v1 controller. Ideally I would like to call it like this:
site.com/api/v1/verify.xml
But right now I can't get the .xml to work. I have the following route so far:
map.namespace :api do |api|
api.connect ':controller/:action/:id'
end
I can do /api/v1/verify
but I don't think it is using the route above. For some reason it is still hitting my catch all route also even though it displays the right page.
map.connect '*path', :controller => 'application', :action => 'redirect_main'
So:
1) how do I get the .format
on there?
2) And how do I make it not hit my catch all route?
Upvotes: 3
Views: 1841
Reputation: 38366
If you aren't using named routes or resources, you have to specify every combination of path you want to handle, including the file extension.
Adding api.connect ':controller/:action/:id.:format'
back to your api
namespace will give you access to params[:format]
to respond to.
Upvotes: 1
Reputation: 8461
1) how do I get the .format on there?
api.connect ':controller/:action/:id.:format'
2) And how do I make it not hit my catch all route?
I believe your catch-all route should be the last one on routes.rb
. This way it should work...
Upvotes: 4
Reputation: 6637
Wouldn't you just need to add .:format
?
map.namespace :api do |api|
api.connect ':controller/:action/:id.:format'
end
Upvotes: 1