Closed abrisse closed 12 years ago
Thanks for the report. I don't think this has anything to do with the :shallow option, as when I take that out I still get the same error.
Looking into it.....
It actually doesn't seem to have anything to do with the :shallow option after all. It's a bug in the handling of leading slashes in the path.
The following causes the error:
api_version(:module => "Api::V1", :path => "/v1") do
resources :users, :shallow => true
end
The following works.
api_version(:module => "Api::V1", :path => "v1") do
resources :users, :shallow => true
end
[bploetz:~/tmp/test-api-rails32]> rake routes
v1_users GET /v1/users(.:format) Api::V1/users#index
POST /v1/users(.:format) Api::V1/users#create
new_v1_user GET /v1/users/new(.:format) Api::V1/users#new
edit_v1_user GET /v1/users/:id/edit(.:format) Api::V1/users#edit
v1_user GET /v1/users/:id(.:format) Api::V1/users#show
PUT /v1/users/:id(.:format) Api::V1/users#update
DELETE /v1/users/:id(.:format) Api::V1/users#destroy
Note the leading slash is left off of the :path in the variant that works. This seems to be related to the gsub! that's happening here:
https://github.com/bploetz/versionist/blob/master/lib/versionist/routing.rb#L39
If you use something like match or get instead of resources....
api_version(:module => "Api::V1", :path => "/v1") do
get "/test" => "test#test"
end
You'll see that it "works" but the route names are prefixed by a _ :
[bploetz:~/tmp/test-api-rails32]> rake routes
_v1_test GET /v1/test(.:format) Api::V1/test#test
Whereas this....
api_version(:module => "Api::V1", :path => "v1") do
get "/test" => "test#test"
end
...results in this:
[bploetz:~/tmp/test-api-rails32]> rake routes
v1_test GET /v1/test(.:format) Api::V1/test#test
My suspicion is that the leading underscore that Versionist is adding is causing issues when using resources for some reason, regardless of whether :shallow is present or not.
So try leaving off the leading slash on the :path and see if that helps. I'll add some logic to remove the leading slash if it's present when using the Path strategy.
Removing the leading slash indeed resolves the problem. Thanks Brian!
@abrisse versionist 0.2.3 has been released with this fix. Can you update your Gemfile to depend on versionist 0.2.3, put back the leading slash on your :path and ensure that it works for you?
Works perfectly!
Great, thanks
Hi!
I would like to know if versionist was compatible with the Rails :shallow option ?
(:shallow - If true, paths for nested resources which reference a specific member (ie. those with an :id parameter) will not use the parent path prefix or name prefix.)
Here is my routes.rb :
When running rake routes :