Xandman
Xandman

Reputation: 2003

No route matches on Railstutorial.org

I generated home and contact page thru:

rails generate Pages home contact

did tests to verify and all was okay, now I wanted to add the page "about". I created the about.html.erb through copying the contact.html.erb and pasting then renaming it to about.html.erb. I then changed the content to "Pages#about" instead of "Pages#contact"

I changed route.rb to:

SampleApp::Application.routes.draw do
  get "pages/home"

  get "pages/contact"

  get "pages/about"

then pages_controller.rb to:

def home
  end

  def contact
  end

  def about
  end

Finally added this to pages_controller_spec.rb:

 describe "GET 'about'" do
    it "should be successful" do
      get 'about'
      response.should be_success
    end
  end

on my autotest this was the error:

Failures:
  1) PagesController GET 'about' should be successful
     Failure/Error: get 'about'
     No route matches {:controller=>"pages", :action=>"about"}
     # ./spec/controllers/pages_controller_spec.rb:22:in `block (3 levels) in <top (required)>'

What did I do wrong?

Should I have generated the about page through:

rails generate Pages about

to generate the about page? instead of copy-paste?

Upvotes: 0

Views: 693

Answers (3)

Forrest Ye
Forrest Ye

Reputation: 826

This is because spork doesn't reload your routes. Put this in your spec_helper.rb to force spork to reload routes "each_run" (credit: http://jinpu.wordpress.com/2011/03/13/reload-routes-with-spork-each-run/)

Spork.each_run do
  # This code will be run each time you run your specs.
  require File.expand_path("../../config/routes", __FILE__)
end

Upvotes: 2

reneruiz
reneruiz

Reputation: 2484

Samesies: restart spork

It was only after I quit in frustration and came back an hour later for another look that it worked.

Upvotes: 0

Tornskaden
Tornskaden

Reputation: 2273

Had the same problem. In my case the problem was that 'spork' needed a restart

Upvotes: 5

Related Questions