0

我正在使用 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 请求中没有任何数据。

这种行为有原因吗?还是我做错了什么?

4

1 回答 1

1

我做了一些挖掘,似乎有一个路线格式的配置。试试这个

# config/initializers/jsonapi.rb
JSONAPI.configure do |config|
  config.route_format = :underscored_route
end

这应该将路线变成“/publishing_houses”而不是“publishing-houses”,这将使它们与您正在使用的其他库兼容。

于 2016-08-07T22:18:03.397 回答