Question

This is the second time this has happened - once while using Ruby Mine, and once while going the pure text route using Sublime Text 2.

Everything works great at first - the local host loads up fine, the three created static pages load fine - and then, boom, it just breaks. I am almost 100% positive that this is happening immediately after I merge the master branch with the static-pages branch. The static pages just won't load (on either branch - I tried switching back and forth to see if things were still functioning on one branch, but nope).

Instead, I get the following error:

No route matches [GET] "/home"

(same error message applies to the other two pages)

Here's the full trace for the home page:

Rails.root: C:/Sites/sample

actionpack (4.0.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.0.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.8) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.8) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.8) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.8) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.8) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.8) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.8) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.8) lib/rails/engine.rb:511:in `call'
railties (4.0.8) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
I:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
I:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
I:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Routes

Routes match in priority from top to bottom
Helper              HTTP Verb      Path                         Controller#Action
Path / Url          
static_pages_home_url   GET     /static_pages/home(.:format)    static_pages#home
static_pages_help_url   GET     /static_pages/help(.:format)    static_pages#help
static_pages_about_url  GET     /static_pages/about(.:format)   static_pages#about 

The routes.rb file is as follows (which matches the tutorial):

Sample::Application.routes.draw do
  get "static_pages/home"
  get "static_pages/help"
  get "static_pages/about"

end

The static_pages_controller.rb file is as follows (which, again, matches the tutorial):

class StaticPagesController < ApplicationController

  def home
  end

  def help
  end

  def about
  end
end

I am at a complete loss on this.

I found this: Routing Error during "Ruby on Rails-Tutorial" I double-checked, and yes, I am in C:\Sites\sample when I launch the server, so I don't think that's the issue, unless something is happening after I merge that would change where I need to launch the server?

And I found this: Rails Server Routing Error but the routes are there in my routes.rb file using the same syntax as in the tutorial.

On the off-chance it's needed, here's the static_pages_spec.rb file RSpec is using for testing:

require 'spec_helper'

describe "StaticPages" do

  describe "Home page" do
    it "should have the content 'Sample App'" do
      visit '/static_pages/home'
      expect(page).to have_content('Sample App')
    end

    it "should have the title 'Home'" do
        visit '/static_pages/home'
        expect(page).to have_title("Ruby on Rails Tutorial Sample App | Home")
    end
  end

  describe "Help page" do
    it "should have the content 'Help'" do
        visit '/static_pages/help'
        expect(page).to have_content('Help')
    end

        it "should have the title 'Help'" do
        visit '/static_pages/help'
        expect(page).to have_title("Ruby on Rails Tutorial Sample App | Help")
    end
  end

  describe "About page" do
    it "should have the content 'About Us'" do
        visit '/static_pages/about'
        expect(page).to have_content('About Us')
    end

        it "should have the title 'About Us'" do
        visit '/static_pages/about'
        expect(page).to have_title("Ruby on Rails Tutorial Sample App | About Us")
    end
  end
end
Was it helpful?

Solution

You don't have a route to /home hence why your getting No route matches [GET] "/home" You have a route to /static_pages/home (and if you enter that into your url browser you will see your home page) (ie localhost:3000/static_pages/home)

You can map /home to static_pages home by adding this to your routes.rb

get '/home', to: 'static_pages#home'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top