Routing Error

Generated a controller "rails generate controller say" and then added a method to id named hello as. def hello end                             Made a file /app/view/say/hello.html.erb as "sudo gedit hello.html.erb" and add follwoing to it

<html> <head> <title>Hello, Rails!</title> </head> <body> <h1>Hello from Rails!</h1> </body> </html>

                            Browse to locahost:3000/say/hello gives the error Routing Error No route matches "/say/hello.html.erb"

Amrit pal

amritpal p. wrote in post #995070: Generated a controller "rails generate controller say" and then added a method to id named hello as. def hello end                             Made a file /app/view/say/hello.html.erb as "sudo gedit hello.html.erb" and add follwoing to it

<html> <head>   <title>Hello, Rails!</title> </head> <body>   <h1>Hello from Rails!</h1> </body> </html>

Browse to locahost:3000/say/hello gives the error Routing Error No route matches "/say/hello.html.erb"

Amrit pal

You need to add the route to config/routes.rb so that your application knows how to match the URL to a given controller/action pair or use a more vague route definition:

match ':controller(/:action(/:id))'

That way, any requests for /say will match this route unless any more specific matching routes are found earlier in the file.

Also, please use a layout file for your HTML tags so that you don't have to use <head> and <body> tag definitions in *every* view in order to pass w3c validation.

ok Thanks

very strange again !! say_controller.rb looks like:

class SayController < ApplicationController def hello @timee =Time.now end def goodbye end end

/app/view/say/hello.html.erb looks like:

It is now <%= @timee%> <a href="/say/goodbye">Goodbye</a>

/app/view/say/goodbye.html.erb looks like:

<h1>Good bye buddy!</h1>

                                                     When i click on Goodbye link given in hello.html.erb file it says        "No route matches "/say/goodbye" .It made me desperate.i dont know what this error persist.

Please guide.

Thanks

amritpal p. wrote in post #995323:

class SayController < ApplicationController def hello   @timee = Time.now end def goodbye

end end

/app/views/say/hello.html.erb looks like:

It is now <%= @timee %> <a href="/say/goodbye">Goodbye</a>

Instead of <a href="/say/goodbye">Goodbye</a>, use <%= link_to "Goodbye", :action => "goodbye" %>

/app/views/say/goodbye.html.erb looks like:

<h1>Good bye buddy!</h1>

When i click on Goodbye link given in hello.html.erb file it says "No route matches "/say/goodbye". It made me desperate. I don't know why this error persists.

Have you set up a route for it in config/routes.rb?

> amritpal p. wrote in post #995323:

> class SayController < ApplicationController > def hello > @timee = Time.now > end > def goodbye

> end > end

> /app/views/say/hello.html.erb looks like:

> It is now <%= @timee %> > <a href="/say/goodbye">Goodbye</a>

Instead of <a href="/say/goodbye">Goodbye</a>, use <%= link_to "Goodbye", :action => "goodbye" %>

                It didn't help,error says        No route matches {:controller=>"say", :action=>"goodbye"}

> /app/views/say/goodbye.html.erb looks like:

> <h1>Good bye buddy!</h1>

> When i click on Goodbye link given in hello.html.erb file it says > "No route matches "/say/goodbye". It made me desperate. I don't > know why this error persists.

Have you set up a route for it in config/routes.rb?

             yes is set up as:

           root :to => "say#hello"

Thanks

So you think that the above line, which says route '/' to say#hello' is going to route /say/goodbye somewhere? As I said previously you need to re-read the Rails Guide on routing. Read every line and make sure you understand it. If you think you already understand it then you are mistaken.

Colin

amritpal p. wrote in post #995439:

Instead of <a href="/say/goodbye">Goodbye</a>, use <%= link_to "Goodbye", :action => "goodbye" %>

It didn't help, error says: No route matches {:controller=>"say", :action=>"goodbye"}

Of course it didn't, but you are working in a Rails environment so you ought to be using Rails conventions and helpers like 'link_to'.

/app/views/say/goodbye.html.erb looks like:

<h1>Good bye buddy!</h1>

When I click on Goodbye link given in hello.html.erb file it says "No route matches "/say/goodbye". It made me desperate. I don't know why this error persists.

Have you set up a route for it in config/routes.rb?

Yes is set up as: root :to => "say#hello" Thanks

I think you need to take Colin's advice - once you're *absolutely* confident you understand the fundamentals of routing in Rails 3, you need to check the setup of your Rails environment against a working example, maybe by searching online or using one of your working applications (if you have one).

>> > amritpal p. wrote in post #995323:

>> > class SayController < ApplicationController >> > def hello >> > @timee = Time.now >> > end >> > def goodbye

>> > end >> > end

>> > /app/views/say/hello.html.erb looks like:

>> > It is now <%= @timee %> >> > <a href="/say/goodbye">Goodbye</a>

>> Instead of <a href="/say/goodbye">Goodbye</a>, use <%= link_to >> "Goodbye", :action => "goodbye" %> > It didn't help,error says > No route matches {:controller=>"say", :action=>"goodbye"}

>> > /app/views/say/goodbye.html.erb looks like:

>> > <h1>Good bye buddy!</h1>

>> > When i click on Goodbye link given in hello.html.erb file it says >> > "No route matches "/say/goodbye". It made me desperate. I don't >> > know why this error persists.

>> Have you set up a route for it in config/routes.rb? > yes is set up as:

> root :to => "say#hello"

So you think that the above line, which says route '/' to say#hello' is going to route /say/goodbye somewhere?

      No it will not route to /say/goodbye,but it will route to /say/ hello which has a link to /say/goodbye method. Can you tell me solution?

Thanks As I said previously you

amritpal p. wrote in post #995520:

> root :to => "say#hello"

So you think that the above line, which says route '/' to say#hello' is going to route /say/goodbye somewhere?

      No it will not route to /say/goodbye,but it will route to /say/ hello which has a link to /say/goodbye method.

Umm... no it won't, as evidenced by your own statement:

When i click on Goodbye link given in hello.html.erb file it says "No route matches "/say/goodbye".

Take a look at your log file and see what your Rails application is receiving when you click the "Goodbye" link in the browser. Review your routes.rb file. If you run a

rake routes > routes.lst

then look at the routes.lst file, you'll know exactly what routes you have available in your application. Next, re-read the Rails guide on routing.

I hesitate to just say "type this code in here and it will work" because that doesn't lead to learning or understanding. Directing you to look at your log file to see what your application is receiving, seeing what Rails has as routes for your application, and pointing to the correct reference for reading may.

It's the old "give a man a fish..." strategy.