Rails Routing with namespace and format (for api)

I know this is not RESTful, but so far I am trying to configure the api / v1 controller. Ideally, I would call it as follows:

site.com/api/v1/verify.xml

But right now I cannot get .xml to work. So far I have the following route:

map.namespace :api do |api|
  api.connect ':controller/:action/:id'
end

I can do it /api/v1/verify, but I don’t think it uses the route above. For some reason, it still hits my path, even if it displays the correct page.

map.connect '*path', :controller => 'application', :action => 'redirect_main'

So:
1) how do I get .formatthere?
2) And how do I get him not to hit my route?

+3
source share
3 answers

1) how can i get .format here?

api.connect ':controller/:action/:id.:format'

2) ?

, routes.rb. , ...

+4

, , , .

api.connect ':controller/:action/:id.:format' api params[:format] .

+1

Didn't you just need to add .:format?

map.namespace :api do |api|
  api.connect ':controller/:action/:id.:format'
end
+1
source

Source: https://habr.com/ru/post/1747037/


All Articles