bploetz / versionist

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

Support for Rails 5 #74

Closed derekprior closed 8 years ago

derekprior commented 8 years ago

The following declaration works with Rails 4.2.x:

  namespace :api do
    api_version(
      module: "V1",
      header: {
        name: "Accept",
        value: "application/vnd.hub+json; version=1",
      },
      defaults: { format: :json },
    ) do
      resources :people
    end
  end

When running with Rails 5, we get:

ArgumentError: 'api/V1/people' 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
johnrees commented 8 years ago

I just ran into this and temporarily fixed it using a lowercase module name module: "v1"

bploetz commented 8 years ago

Ah yes, I thought this sounded familiar. We first ran into this problem when Rails 4 was released, as they changed it so that constant names (i.e. upper case module names) were no longer accepted in routes, and had to be lowercase. I had added logic to deal with this (see https://github.com/bploetz/versionist/blob/master/lib/versionist/routing.rb#L72-L83), but now that Rails 5 is a thing, I'll change this to apply to versions of Rails >= 4.

One sec, I'll push up a branch for you guys to try......

bploetz commented 8 years ago

@derekprior @johnrees Can you point your Gemfile at the following branch, remove your manual fixes to the module name used by api_version, and see if this works for you now on Rails 5?

gem 'versionist', :git => 'https://github.com/bploetz/versionist.git', :branch => 'fix/issue74'
seevee commented 8 years ago

@bploetz Successfully reproduced on Rails 5.0.0.beta3 with master. The issue74 branch solves this issue for me.

bploetz commented 8 years ago

versionist 1.5.0 has been released with this fix. Thanks everyone.