我遵循此How To但我没有路线匹配错误...
我有这个routes.rb:
@Configuration
class MyConfig{
public NewsService NewsService () { return new Newservice(); }
Rake Routes:
# config/routes.rb
require 'api_constraints'
Rails.application.routes.draw do
namespace :api, defaults: { format: :json }, constraints: { subdomain: 'api' }, path: '/' do
scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
resources :products, only: [:index, :show, :create, :destroy]
end
end
end
这是错误:
api_products GET /products(.:format) api/v1/products#index {:format=>:json, :subdomain=>"api"}
POST /products(.:format) api/v1/products#create {:format=>:json, :subdomain=>"api"}
api_product GET /products/:id(.:format) api/v1/products#show {:format=>:json, :subdomain=>"api"}
DELETE /products/:id(.:format) api/v1/products#destroy {:format=>:json, :subdomain=>"api"}
答案 0 :(得分:2)
我认为请求在子域约束下被拒绝。我认为您向http://localhost:3000/produtcts提出了请求,但您需要一些网址,例如 http://api。**** / products 。有一个指南如何在本地http://shapeshed.com/developing-subdomain-rails-sites-locally/