ruby on rails - No route matches [GET] /users -
edit: resource , controller has been pluralized, feedback wrote in comments. problem still persists.
i'm new rails , i'm trying create rest api in rails 4. i've got routing error when seek execute request on user
ressource : http://api.localhost:3000/users
no route matches [get] "/users"
but, when execute command 'rake routes' on terminal, can see there /users
route:
api_users /users(.:format) api/users#index {:subdomain=>"api"} post /users(.:format) api/users#create {:subdomain=>"api"} new_api_user /users/new(.:format) api/users#new {:subdomain=>"api"} edit_api_user /users/:id/edit(.:format) api/users#edit {:subdomain=>"api"} api_user /users/:id(.:format) api/users#show {:subdomain=>"api"} patch /users/:id(.:format) api/users#update {:subdomain=>"api"} set /users/:id(.:format) api/users#update {:subdomain=>"api"} delete /users/:id(.:format) api/users#destroy {:subdomain=>"api"}
here content of route.rb
file:
rails.application.routes.draw # create rousources in subdomain api namespace :api, path: '/', constraints: { subdomain: 'api' } resources :users end end
and users_controller.rb
file:
module api class userscontroller < applicationcontroller def index @users = user.all render json: users, status: 200 end end end
any suggestion?
edit: resource , controller has been pluralized, feedback wrote in comments. problem still persists.
rails determines subdomain
of url taking part host address in front end of sec dot right. in illustration utilize host api.localhost
. rails determine empty subdomain that.
therefore suggest configure domain api.my_app.dev
in hosts
file. allow rails determine right subdomain part api
host.
after did local server should respond to: http://api.my_app.dev:3000/users
btw. chose tld dev
, because default if utilize tool pow.
ruby-on-rails ruby routes
No comments:
Post a Comment