Closed cheshire137 closed 10 years ago
@moneypenny what do you have within the api_version
block there?
For the sake of completeness, this works for me locally using a standard resources
within the api_version
:
Rails.application.routes.draw do
scope '/api' do
api_version(module: 'V1', path: {value: '1'}, default: true, defaults: {format: :json}) do
resources :foos
end
end
[bploetz:~/workspace/versionist-test-apis/test-api-rails41] bundle exec rake routes
Prefix Verb URI Pattern Controller#Action
GET /api/1/foos(.:format) v1/foos#index {:format=>:json}
POST /api/1/foos(.:format) v1/foos#create {:format=>:json}
new_1_foo GET /api/1/foos/new(.:format) v1/foos#new {:format=>:json}
edit_1_foo GET /api/1/foos/:id/edit(.:format) v1/foos#edit {:format=>:json}
GET /api/1/foos/:id(.:format) v1/foos#show {:format=>:json}
PATCH /api/1/foos/:id(.:format) v1/foos#update {:format=>:json}
PUT /api/1/foos/:id(.:format) v1/foos#update {:format=>:json}
DELETE /api/1/foos/:id(.:format) v1/foos#destroy {:format=>:json}
default_foos GET /api/foos(.:format) v1/foos#index {:format=>:json}
POST /api/foos(.:format) v1/foos#create {:format=>:json}
new_default_foo GET /api/foos/new(.:format) v1/foos#new {:format=>:json}
edit_default_foo GET /api/foos/:id/edit(.:format) v1/foos#edit {:format=>:json}
default_foo GET /api/foos/:id(.:format) v1/foos#show {:format=>:json}
PATCH /api/foos/:id(.:format) v1/foos#update {:format=>:json}
PUT /api/foos/:id(.:format) v1/foos#update {:format=>:json}
DELETE /api/foos/:id(.:format) v1/foos#destroy {:format=>:json}
Interesting. I'm using version 1.4.0 of the gem. I bet the problem was I have a mixture of resources
like you show but also get 'localizations/:lang', to: 'localization#show', as: :localization
. I'll see if I can omit the as
and get rid of the error.
I also discovered that removing the scope '/api'
and instead doing just api_version(module: 'V1', path: {value: 'api/1'}, default: true, defaults: {format: :json}) do
also works and gives me the URL I want, so I may stick with that.
@moneypenny yeah, if I add that get 'localizations/:lang', to: 'localization#show', as: :localization
line within my api_version
I get the same error. The line in action_dispatch it's barfing on is this:
As you can see, the route name has to start with an underscore or a lower case letter. Omitting the :as
option gets rid of the problem (but obviously gives you a different route name):
[bploetz:~/workspace/versionist-test-apis/test-api-rails41] bundle exec rake routes
Prefix Verb URI Pattern Controller#Action
GET /api/1/localizations/:lang(.:format) v1/localization#show {:format=>:json}
default GET /api/localizations/:lang(.:format) v1/localization#show {:format=>:json}
I'm fine closing this issue, I have a couple workarounds. Thanks!
Cool, thanks @moneypenny
I want routes like /api/1/my_controller, so I used the following:
However, this causes the following error:
How can I have a path parameter that starts with a number?