我正在使用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
然而我注意到一些奇怪的事情。如果我按照这样的方式进入publish_houses的路径:http://localhost:3000/publishing_houses它表示路由/页面不存在。但是,如果我带着破折号而不是出版社之间的下划线去http://localhost:3000/publishing-houses,我会收到我想要的回复。
问题出在我的ember应用程序中,我已经检查了控制台并使用此url:http://localhost:3000/publishing_houses使用下划线请求数据,因此我的ember请求中没有得到任何数据。
这种行为有原因吗?或者我做错了什么?
答案 0 :(得分:1)
我做了一些挖掘,似乎有一个路由格式的配置。试试这个
# config/initializers/jsonapi.rb
JSONAPI.configure do |config|
config.route_format = :underscored_route
end
那应该把路线变成" / publishing_houses"而不是"出版社"这将使它们与您正在使用的其他库兼容。