bploetz / versionist

A plugin for versioning Rails based RESTful APIs.
MIT License
972 stars 51 forks source link

You don't have any routes defined! #65

Closed starkovv closed 10 years ago

starkovv commented 10 years ago

rails 4.1.0 or rails 4.1.5 + versionist 1.3.0

./config/routes.rb:

Rails.application.routes.draw do

  api_version(module: 'V1', header: { name: 'Accept', value: 'application/hasl+json; version=1', default: true }) do
    resources :feedbacks, only: [:post]
  end

end

Console:

$ bundle exec rake routes
You don't have any routes defined!

Please add some routes in config/routes.rb.

For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html.
bploetz commented 10 years ago

Thanks for reporting this @starkovv. Looking into it......

bploetz commented 10 years ago

Oh.....duh. This isn't a bug in versionist. This is a bug in your routes. If you take versionist out of the picture and just have your resources line in config/routes.rb you'll get the same error:

config/routes.rb:

Rails.application.routes.draw do
    resources :feedbacks, only: [:post]
end
> bundle exec rake routes
You don't have any routes defined!

Please add some routes in config/routes.rb.

For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html.

This is because the symbols passed in the :only option must match the action method names that map to the CRUD verbs:

http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

So what you want is this instead:

    resources :feedbacks, only: [:create]

When you fix this and add versionist back to the mix, you'll see it works correctly:

config/routes.rb:

Rails.application.routes.draw do
  api_version(module: 'V1', header: { name: 'Accept', value: 'application/hasl+json; version=1', default: true }) do
    resources :feedbacks, only: [:create]
  end
end
> bundle exec rake routes
parent_resource.actions: [:create]
   Prefix Verb URI Pattern          Controller#Action
feedbacks POST /feedbacks(.:format) v1/feedbacks#create
starkovv commented 10 years ago

My fault. Thanks @bploetz !