Jeff Y.
Jeff Y.

Reputation: 41

Rails 3 can't find route to static page

Am working my way thru Ruby on Rails Tutorial: Learn Rails by Example. I'm in the section entitled Mostly Static Pages.

I get an error after I create an HTML page in the public directory which is called public/hello.html and should appear as in Figure 3.3. My problem is that when I try to create the page and make it appear at localhost:3000/hello.html I don't see the rendered page. Instead, I get an error which says "Routing error No route matches "/ hello.html"

I have not made any changes to the routing; I thought that Rails was supposed to be smart enough to find "hello.html" because it's in the same directory as the "public/index.html" page and the name of the page is "hello.html"?

Can you please explain?

Upvotes: 3

Views: 2299

Answers (5)

AguNnamdi
AguNnamdi

Reputation: 1

Review your app directory again and make sure you save the file in (my case) :

C:\Users\Nnamdi\rails_projects\sample_app\public\hello.html

I had the same issue but realized that I did not save it in the right directory ..The solution above should work..cheers

Upvotes: 0

Paul
Paul

Reputation: 1

Move the file to the Public folder. That did the trick for me.

The hint I used is that Rails serves the Public folder by default. So I figured, if I put it in the Public folder, that ought to work. You'll see it's in line with the index file, so I think that's proof, too.

Upvotes: 0

pirate
pirate

Reputation: 11

You're following an old guide. A newer version

http://ruby.railstutorial.org/chapters/static-pages#sec:green

tells you that you need to modify the routes.rb in the config folder. I spent about an hour crying about this.

Upvotes: 1

Kevin Novak
Kevin Novak

Reputation: 41

If you're like me and powering through the book, I left the server running from the prior chapter, so it was still loading index.html from the demo_app directory.

Upvotes: 4

Ryan Bigg
Ryan Bigg

Reputation: 107718

Are you sure you typed this correctly? It looks like you've typed "localhost:3000/[space]hello.html" rather than "localhost:3000/hello.html". Please double check.

Upvotes: 0

Related Questions