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

Hello, Rails!

Hello from Rails!

                        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

Hello, Rails!

Hello from Rails!

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 and tag definitions in every view in order to
pass w3c validation.

On Apr 26, 12:09pm, Pale H. [email protected] wrote:

Hello, Rails!

Also, please use a layout file for your HTML tags so that you don’t have
to use and tag definitions in every view in order to
pass w3c validation.
ok
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 %>
Goodbye

Instead of Goodbye, use <%= link_to
“Goodbye”, :action => “goodbye” %>

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

Good bye buddy!

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?

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%>
Goodbye

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

Good bye buddy!

                                                 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

On 28 April 2011 02:37, amrit pal pathak [email protected]
wrote:

   It didn't help,error says

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? 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

On Apr 27, 10:52am, Pale H. [email protected] wrote:

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

It is now <%= @timee %>
Goodbye

Instead of Goodbye, 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:

Good bye buddy!

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

amritpal p. wrote in post #995439:

Instead of Goodbye, 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:

Good bye buddy!

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).

On Apr 28, 3:25am, Colin L. [email protected] wrote:

end
No route matches {:controller=>“say”, :action=>“goodbye”}
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:

On Apr 28, 3:25am, Colin L. [email protected] wrote:

 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.

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