market_place_api icon indicating copy to clipboard operation
market_place_api copied to clipboard

ActionController::RoutingError (No route matches [GET] "/api/v1/users/1")

Open Orinameh opened this issue 10 years ago • 14 comments

Hi, when i try to test my endpoint for the first user, i get the html structure with 404 not found is title. The webrick server shows ....No route matches[GET]"/api/v1/users/1". Any help from your end?

Orinameh avatar Dec 07 '15 18:12 Orinameh

I'd be interested in a solution here as well.

lesreaper avatar Dec 10 '15 03:12 lesreaper

@Orinameh Are u using prax? If you are not using prax. I suggest you use it. It makes following the book easier. Else you remove "constraints: { subdomain: 'api' }" from the route.rb file.

Innarticles avatar Dec 13 '15 13:12 Innarticles

@Orinameh did you made it work?

kurenn avatar Dec 14 '15 03:12 kurenn

@Innarticles I use prax while following the tutorial and still get same errors..@Kurenn nope

Orinameh avatar Dec 15 '15 01:12 Orinameh

@Orinameh How does your routes file looks like?

kurenn avatar Dec 15 '15 18:12 kurenn

@kurenn Hey, I am also having this problem! Below is my routes file.

    require 'api_constraints'
Rails.application.routes.draw` do

  devise_for :users
  #API Definition
    namespace :api, defaults: { format: :json}, 
                constraints: { subdomain: 'api' }, path: '/'  do

        scope module: :v1,
                    constraints: ApiConstraints.new(version: 1, default: true) do


        resources :users, :only => [:show]
    end
  end
end
`

oseifrimpong avatar Feb 12 '16 16:02 oseifrimpong

Try to move the devise_for :users call below the namespace for the API

kurenn avatar Feb 12 '16 23:02 kurenn

@kurenn I am still having the same problem. I have no idea why. I have done what you asked me to do.

oseifrimpong avatar Feb 13 '16 08:02 oseifrimpong

@Orinameh @lesreaper This is what worked for me:

require 'api_constraints'

MarketPlaceApi::Application.routes.draw do
  resources :articles
  mount SabisuRails::Engine => "/sabisu_rails"

  # devise_for :users
  namespace :api, defaults: { format: :json }, constraints: { subdomain: 'api' }, path: '/' do
    # devise_for :users
    scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
      # devise_for :users
      resources :users, :only => [:show, :create, :update, :destroy] do
        resources :products, :only => [:create, :update, :destroy]
        resources :orders, :only => [:index, :show, :create]
      end
      devise_for :users
      resources :sessions, :only => [:create, :destroy]
      resources :products, :only => [:show, :index]
    end
  end

  resources :users, :only => [:show, :new]

end

Also note that the tutorial used an older version of rails.

Innarticles avatar Feb 13 '16 09:02 Innarticles

@kurenn I am trying to test the user endpoints before the before I install Sabisu. I have tried bringing the devise_for :users below the namespace for the API but I seem to get the same error. which is ActionController::RoutingError (No route matches [GET] "/api/v1/users/1") Any other thing you think might be wrong?

This is my routes.rb once again after doing what you asked me to do.

`require 'api_constraints'

MsosiApi::Application.routes.draw do



  # devise_for :users
  namespace :api, defaults: { format: :json }, constraints: { subdomain: 'api' }, path: '/' do
    # devise_for :users
    scope module: :v1, constraints: ApiConstraints.new(version: 1, default: true) do
      # devise_for :users
      resources :users, :only => [:show, :create, :update, :destroy] 


      end
    end
     devise_for :users
end`

oseifrimpong avatar Feb 14 '16 08:02 oseifrimpong

I see, you have to update your routes.rb file.

The thing with that is that you are trying to run the api through a subdomain a accessing this endpoint localhost:3000/api/v1/users/1 and you need to go api.marketplaceapi.dev/users/1 or whichever the endpoint you are trying yo reach.

kurenn avatar Mar 22 '16 23:03 kurenn

To use localhost:3000/api/v1/users/1 change routes.rb to this namespace :api, defaults: { format: :json } do namespace :v1 do devise_for :users resources :users, :only => [:show] end end

phani627 avatar Jan 28 '17 14:01 phani627

funny enough I had to change constraints: { subdomain: :api } to constraints: { subdomain: 'api' }

AndreiMotinga avatar Jun 13 '17 14:06 AndreiMotinga

@AndreiMotinga that is weird, but hey, as long as you made it worked. Should I close this issue then?

kurenn avatar Jun 13 '17 19:06 kurenn