我使用了一个测试应用程序,使用了ember前端,并使用jsonapi-resources来构建rails api。我在rails应用程序中的路径定义如下
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
jsonapi_resources :books
jsonapi_resources :authors
jsonapi_resources :publishing_houses
end然而,我注意到了一些奇怪的事情。如果我像这样转到publishing_houses的路径:http://localhost:3000/publishing_houses,它会显示路由/页面不存在。然而,如果我在http://localhost:3000/publishing-houses上使用破折号而不是出版社之间的下划线,我会得到我想要的响应。
问题出在我的ember应用程序中,我检查了控制台,它使用url:http://localhost:3000/publishing_houses和下划线请求数据,所以我在ember请求中没有得到任何数据。
这种行为是有原因的吗?还是我做错了什么?
发布于 2016-08-08 06:18:03
我做了一些调查,似乎有一个路由格式的配置。尝尝这个
# config/initializers/jsonapi.rb
JSONAPI.configure do |config|
config.route_format = :underscored_route
end这应该会将路由转换为"/publishing_houses“,而不是”publishing house“,这将使它们与您正在使用的其他库兼容。
https://stackoverflow.com/questions/38818738
复制相似问题