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

Please somebody help me.

It looks like you were trying to access “/say/hello.html.erb” as the URL
rather than “say/hello”

On 26 Apr 2011, at 10:51, amrit pal pathak [email protected]
wrote:

Generated a controller “rails generate controller say” and then added
a method to id named hello as.

You need to add a route to the action. Colin discussed this with you at
some length last week.

Fred

On Apr 26, 7:54am, Frederick C. [email protected]
wrote:

On 26 Apr 2011, at 10:51, amrit pal pathak [email protected] wrote:

Generated a controller “rails generate controller say” and then added
a method to id named hello as.

You need to add a route to the action. Colin discussed this with you at some
length last week.
Yes he discussed ,but thats was only if i want to see hello
action at “localhost:3000”. But to see hello method at “localhost:
3000/say/hello” doesn’t need any routing settings.Still it is not
showing it
Why?

Thanks

On 26 April 2011 13:22, amrit pal pathak [email protected]
wrote:

Yes he discussed ,but thats was only if i want to see hello
action at “localhost:3000”. But to see hello method at “localhost:
3000/say/hello” doesn’t need any routing settings.

Yes it does. Go and read the Rails Guide on routing again.

Colin

On Apr 26, 8:31am, Colin L. [email protected] wrote:

You need to add a route to the action. Colin discussed this with you at some
length last week.
Yes he discussed ,but thats was only if i want to see hello
action at “localhost:3000”. But to see hello method at “localhost:
3000/say/hello” doesn’t need any routing settings.

Yes it does. Go and read the Rails Guide on routing again.
ok .Done
" root :to => “say#hello”". Still unsussess.
No route matches “/say/hello”

Thank you.

amritpal p. wrote in post #995099:

ok .Done
“root :to => “say#hello””. Still unsussess.
No route matches “/say/hello”

Thank you.

Quoted from the Rails guide: “You should put the root route at the end
of the file. You also need to delete the public/index.html.erb file for
the root route to take effect.”

Rails will look in app/controllers for a controller named
‘say_controller’. Inside that, it will search for an action with the
name ‘hello’ and then will render that action using hello.html.erb in
app/views/say

If it is not doing this, then there is something you’ve omitted when
trying to explain the issue.

What is the output of rake routes?

What happens if you match ‘say’, :to => ‘say#hello’ and navigate your
browser to /say?

Please see the following screencasts for routing in Rails 3.x:

On Apr 26, 9:26am, Pale H. [email protected] wrote:

the root route to take effect."
it helped.but without deleting that file and setting routing
path to say controller “localhost:3000/say/hello” wasn’t work?i think
it should work

What happens if you match ‘say’, :to => ‘say#hello’ and navigate your
browser to /say?
it said " No route matches “/say/hello”".
Thanks

amritpal p. wrote in post #995108:

On Apr 26, 9:26am, Pale H. [email protected] wrote:
the root route to take effect."
it helped but without deleting that file and setting routing
path to say controller “localhost:3000/say/hello” wasn’t work? i think
it should work

What happens if you match ‘say’, :to => ‘say#hello’ and navigate your
browser to /say?

it said " No route matches “/say/hello”".
Thanks

Please paste your routes.rb file here or use http://pastie.org/ if it’s
too long.

On Apr 26, 10:01am, Pale H. [email protected] wrote:

it said " No route matches “/say/hello”".
Thanks

Please paste your routes.rb file here or usehttp://pastie.org/if it’s
too long.

Age::Application.routes.draw do

The priority is based upon order of creation:

first created → highest priority.

Sample of regular route:

match ‘products/:id’ => ‘catalog#view’

Keep in mind you can assign values other than :controller

and :action

Sample of named route:

match ‘products/:id/purchase’ => ‘catalog#purchase’, :as

=> :purchase

This route can be invoked with purchase_url(:id => product.id)

Sample resource route (maps HTTP verbs to controller actions

automatically):

resources :products

Sample resource route with options:

resources :products do

member do

get ‘short’

post ‘toggle’

end

collection do

get ‘sold’

end

end

Sample resource route with sub-resources:

resources :products do

resources :comments, :sales

resource :seller

end

Sample resource route with more complex sub-resources

resources :products do

resources :comments

resources :sales do

get ‘recent’, :on => :collection

end

end

Sample resource route within a namespace:

namespace :admin do

# Directs /admin/products/* to Admin::ProductsController

# (app/controllers/admin/products_controller.rb)

resources :products

end

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

just remember to delete public/index.html.

root :to => “say#hello”

See how all your routes lay out with “rake routes”

This is a legacy wild controller route that’s not recommended for

RESTful applications.

Note: This route will make all actions in every controller

accessible via GET requests.

match ‘:controller(/:action(/:id(.:format)))’

end

Amrit pal

amritpal p. wrote in post #995117:

Please paste your routes.rb file here or use http://pastie.org/ if it’s
too long.

Age::Application.routes.draw do
root :to => “say#hello”

See how all your routes lay out with “rake routes”

end

Amrit pal

What is the output of rake routes? This will show you “how all your
routes lay out”.

Try changing the first line of your routes.rb file to:
Age::Application.routes.draw do |map|