Open Orinameh opened 8 years ago
I'd be interested in a solution here as well.
@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.
@Orinameh did you made it work?
@Innarticles I use prax while following the tutorial and still get same errors..@Kurenn nope
@Orinameh How does your routes file looks like?
@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
`
Try to move the devise_for :users
call below the namespace for the API
@kurenn I am still having the same problem. I have no idea why. I have done what you asked me to do.
@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.
@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`
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.
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
funny enough I had to change constraints: { subdomain: :api }
to constraints: { subdomain: 'api' }
@AndreiMotinga that is weird, but hey, as long as you made it worked. Should I close this issue then?
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?