没有路线匹配[GET]“/ products”

时间:2016-03-02 18:29:01

标签: api ruby-on-rails-4 versioning

我遵循此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"}

1 个答案:

答案 0 :(得分:2)

我认为请求在子域约束下被拒绝。我认为您向http://localhost:3000/produtcts提出了请求,但您需要一些网址,例如 http://api。**** / products 。有一个指南如何在本地http://shapeshed.com/developing-subdomain-rails-sites-locally/