Closed steveklabnik closed 12 years ago
@steveklabnik, it doesn't: https://github.com/rails/rails/issues/4127#issuecomment-4167613
Word up. Time to write my first patch to Rails. cracks fingers
I would :heart: for rails to have a better mime type parser. I have to special case Accept headers way too often to prevent that missing template error.
Yeah, this Accept header bug in Rails has bitten us at work too.
They've merged a fix into Rails' master branch (which is Rails 4.0.0 beta), but have not back ported it to Rails 3.x yet.
https://github.com/rails/rails/pull/4918
I'll keep an eye on the ticket to get the fix into Rails 3.x that @atambo pointed out, and if/when they do that I'll make sure this works with Versionist as well.
This only fixes q parameters, they should accept arbitrary ones.
Pull requested: https://github.com/rails/rails/pull/5290
Aaaand merged. Damn, jose is fast. :)
high five
I've switched our API to use this variant of the Accept header as suggested by @steveklabnik ....
application/vnd.mycompany.com; version=1
...and it works just fine with Rails 3.1.4 and Versionist 0.2.0. I'll update the README to use this format as an example for the Accept header and close this issue. If anyone out there finds that this isn't working for them, please re-open this issue.
Wooo!
The one gotcha here is with the generators. If you use parameters, you must wrap the Accept header string in quotes, otherwise Thor chops off everything from the semi-colin on. For example:
FAIL:
rails generate versionist:new_api_version v2 V2 header:Accept value:application/vnd.mycompany.com; version=2
route api_version(:module => "V2", :header=>"Accept", :value=>"application/vnd.mycompany.com") do
end
FAIL:
rails generate versionist:new_api_version v2 V2 header:Accept value:application/vnd.mycompany.com;version=2
route api_version(:module => "V2", :header=>"Accept", :value=>"application/vnd.mycompany.com") do
end
SUCCESS:
rails generate versionist:new_api_version v2 V2 header:Accept value:"application/vnd.mycompany.com; version=2"
route api_version(:module => "V2", :header=>"Accept", :value=>"application/vnd.mycompany.com; version=2") do
end
I'm not sure that Rails actually supports this, but instead of
application/vnd.mycompany.com-v1
, acceptapplication/vnd.mycompany.com; version=1
. RFC2046 has examples of this.