user2325154 user2325154 -4 years ago 99
Ruby Question

Rails application not able to detect the route

Even after specifying the route in

routes.rb
my
Rails
application gives me following error when I hit
http://localhost:3000/pages
in the browser.

Ruby Version: 2.2

Rails Version: 5.0

Error:

No route matches [GET] "/pages"


routes.rb

Rails.application.routes.draw do
root 'pages#home'
end


pages_controller.rb

class PagesController < ApplicationController
def home
end
end


home.html.erb

<h2>Welcome Home</h2>
<p>After your long journey through rocky mountains and dry dust bowls you have finally neared the end.</p>

Answer Source

root 'pages#home' only sets up the root route. This will match only localhost:3000/ and not localhost:3000/pages

You want to add something like

get 'pages', to: 'pages#home' to allow /pages to work correctly.

Check out http://edgeguides.rubyonrails.org/routing.html to learn more about routing and your routes.rb file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download