I'm just starting to learn to build api's in rails and have a question getting started. I just want to practice creating routes and controllers but can't get this to work
config/routes.rb
namespace :api, :path => "", :defaults => {:format => :json}, :constraints => {:subdomain => "api"} do
get '/prac' => 'sessions#prac'
end
controllers/api/sessions_controller.rb
def prac
"hello world"
end
When I got to api.localhost:3000/prac, I get (No route matches [GET] "/prac"). I just want the hello world to show up so that I know I am on the right path. Any help would be appreciated.
it's the
subdomain
part.In your case, as the subdomain of
api.localhost
is''
, so this should passOr, you can use a normal local host, like
api.local.com
to make yoursubdomain
check work.