PCR
PCR

Reputation: 275

ember/rails - Strange behavior in rails route containing an underscore

I'm playing around with a tester app using an ember frontend and using jsonapi-resources to build the rails api. My routes in the rails app are defined as follows

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

However I've noticed something strange. If I go to the path for publishing_houses like so: http://localhost:3000/publishing_houses it says the route/page doesn't exist. However if I go to http://localhost:3000/publishing-houses with a dash instead of an underscore between publishing houses, I get the response that I want.

The problem is in my ember app, I've checked the console and it requests data using this url: http://localhost:3000/publishing_houses with the underscore, so I don't get any data back in my ember request.

Is there a reason for this behavior? Or am I doing something wrong?

Upvotes: 0

Views: 96

Answers (1)

kcdragon
kcdragon

Reputation: 1733

I did some digging and there appears to be a config for the route format. Try this

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

That should turn the routes into "/publishing_houses" instead of "publishing-houses" which would make them compatible with the other library you are using.

Upvotes: 1

Related Questions