我正在使用Rails5构建一个简单的应用程序接口。我遵循了这个视频教程here,它使用了jsonapi-resources gem。我走得更远,使用gem实际设置了一些API安全性。
# Gemfile
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
gem 'puma'
#gem 'pg'
gem 'jsonapi-resources', '~> 0.7.1.beta2'
# Security
gem 'rack-attack'
gem 'rack-protection'
gem 'secure_headers'
gem 'brakeman'
gem 'rack-cors'
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'devise'
gem 'devise_token_auth', git: 'git://github.com/lynndylanhurley/devise_token_auth.git'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
gem "omniauth-google-oauth2"
gem 'omniauth-github'
gem 'omniauth-twitch'
gem 'omniauth-instagram'
gem 'pundit'
gem 'dynamic_sitemaps'
gem 'faker'
group :development, :test do
gem 'byebug', platform: :mri
gem 'better_errors'
end
group :development do
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]我已经关注了视频和其他博客帖子,我得到了以下错误:
Started GET "/collections.json" for 14.144.15.10 at 2016-07-19 00:26:03 +0000
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by CollectionsController#index as JSON
Filter chain halted as :ensure_valid_accept_media_type rendered or redirected
Completed 406 Not Acceptable in 289ms (Views: 0.3ms | ActiveRecord: 0.0ms)当我访问集合(http://mydevapp.com/collections.json)的索引页面时,我会得到:
{"errors":[{"title":"Not acceptable","detail":"All requests must use the 'application/vnd.api+json' Accept without media type parameters. This request specified 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'.","code":"406","status":"406"}]}https://stackoverflow.com/questions/38447919
复制相似问题