Routing Error : No route matches "/" (for "Hello World!" action)

My routes.rb reads at the top:

Hello::Application.routes.draw do
match ‘:controller(/:action(/:id(.:format)))’

and then all the commented material it comes with and an “end” at the
end of the file.

But when I type http://localhost:3000 into my browser I get the
following error message:

Routing Error
No route matches “/”

I’m stumped.

Bruce

On Apr 7, 6:51pm, Bruce W. [email protected] wrote:

Routing Error
No route matches “/”

I’m stumped.

The above means that rails can only recognized paths that start with
the name of a controller, optionally followed by an action and id. ‘/’
clearly doesn’t fall into that pattern so you get a routing error. One
way of specifying a default root is by saying

root :to => ‘pages#main’

which says that / should be routed to the main action in
PagesController

Fred

I don’t see that you’ve routed anything to the ‘/’ path.

Your route requires the controller to be in the path.

First step would be to uncomment this

You can have the root of your site routed with “root”

just remember to delete public/index.html.

root :to => “welcome#index”

replacing ‘welcome’ with the controller you want / to route to and
index.html with the action.

Along those lines, usually there is a public/index.html that should
be displayed.

Do you have a file in public/html?

On Apr 7, 11:17am, mainguy [email protected] wrote:

index.html with the action.

Along those lines, usually there is a public/index.html that should
be displayed.

Do you have a file in public/html?

I’m following the instructions in Beginning Rails 3:

$ rails generate controller salutation
Then I added a Hello method to the controller.
Then I created a hello.html.erb template in app/views/salutation.

So the routes.rb file with this code:

Hello::Application.routes.draw do
match ‘:controller(/:action(/:id(.:format)))’
end

is supposed to deliver the desired result of “Hello World!”.

But I went ahead and changed the routes.rb file to read:

Hello::Application.routes.draw do
root :to => “salutation#hello”

That delivers the Hello World! in the browser, but along with the .erb
code:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss
\fcharset0 Arial;}} {*\generator Msftedit
5.41.21.2509;}\viewkind4\uc1\pard\f0\fs20 \par \tab \par \tab\tab
Hello World!
\par \tab \par \par }

What to do?

On Apr 7, 2:16pm, Frederick C. [email protected]
wrote:

I don’t see that you’ve routed anything to the ‘/’ path.

Hello::Application.routes.draw do
What to do?

That looks like you edited your template with an editor that saved it
as an rtf file rather than plain text.

Fred

You’re right! Much thanks to all of the above responders.

But for the sake of learning, can anyone tell me why the Beginning
Rails 3 code doesn’t work, and what exactly is it supposed to do?

Hello::Application.routes.draw do
match ‘:controller(/:action(/:id(.:format)))’
end

Bruce

On Apr 7, 10:02pm, Bruce W. [email protected] wrote:

First step would be to uncomment this
Do you have a file in public/html?
match ‘:controller(/:action(/:id(.:format)))’
code:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss
\fcharset0 Arial;}} {*\generator Msftedit
5.41.21.2509;}\viewkind4\uc1\pard\f0\fs20 \par \tab \par \tab\tab
Hello World!
\par \tab \par \par }

That looks like you edited your template with an editor that saved it
as an rtf file rather than plain text.

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs