bploetz / versionist

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

Routing Error #44

Closed tombu closed 11 years ago

tombu commented 11 years ago

I´m using the code from one of the examples:

api_version(:module => "V1", :header => {:name => "Accept", :value => "application/vnd.mycompany.com; version=1"}) do
    match '/foos.(:format)' => 'foos#index', :via => :get
    match '/foos_no_format' => 'foos#index', :via => :get
    resources :bars
  end

I get the following error:

/Users/Thommy/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-4.0.0/lib/action_dispatch/routing/mapper.rb:239:in `default_controller_and_action': 'V1/foos' is not a supported controller name. This can lead to potential routing problems. See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use (ArgumentError)

I´m using rails-api with ruby 2.0.0. Also the generators break when I try to use the new hash syntax in routes.rb.

Any suggestions how to fix that?

bploetz commented 11 years ago

Looks like Rails 4 now wants camel case module names in config/routes.rb. Changing it to this worked for me locally (note the lower case v in "v1" instead of upper case "V1"):

  api_version(:module => "v1", :header => {:name => "Accept", :value => "application/vnd.mycompany.com; version=1"}) do
    match '/foos.(:format)' => 'foos#index', :via => :get
  end

If you could file a separate issue for the generator/hash syntax problem with more detail, I'd appreciate it.

Thanks.

elfassy commented 11 years ago

It also doesn't support :as option. (Rails 4, Ruby 2)

You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here:
bploetz commented 11 years ago

@elfassy please file a separate issue for the :as option instead of piggybacking on this one

bploetz commented 11 years ago

I forgot I had already filed an issue for the case change to module prefixes:

https://github.com/bploetz/versionist/issues/39

bploetz commented 11 years ago

@tombu I've pushed up a fix for this module name problem in Rails 4. Can you change your Gemfile dependency on Versionist to:

gem 'versionist', :git => 'https://github.com/bploetz/versionist.git', :branch => 'issue39'

Then run bundle update versionist and see if it fixes the problem for you?

tombu commented 11 years ago

Thanks. I´ll give it a try the next days.

tombu commented 11 years ago

Sorry for letting you wait that long. This fix works for me. Thanks a lot

bploetz commented 11 years ago

Cool, thanks @tombu. I've released versionist 1.2.0 with this fix.