-2

In my first approach with Rails I have simply create a void SayController and static hello.rhtml view but when the page http://localhost:3000/say/hello started return me a Routing Error like this:

No route matches [GET] "/say/hello"
Try running rake routes for more information on available routes.

Rails version: 3.2.6

Stefan
  • 109,145
  • 14
  • 143
  • 218
mariobros
  • 859
  • 4
  • 12
  • 31

3 Answers3

1

Seems like you didn't add a route for hello to your config/routes.rb file.

YourApp::Application.routes.draw do
  match 'say/hello' => 'say#hello', :as => :hello
end

This will match route say/hello to controller say (the part before #) and action hello (the part after #).

:as => :hello makes it a named route so you can refer to it as hello_path from within your app.

The error message tells you to run rake routes (from the console) which will show you the existing routes in your app.

Stefan
  • 109,145
  • 14
  • 143
  • 218
0

You should have something in your config/routes.rb to define that route. Try:

match 'say/hello' => 'say#hello', :as => 'say_hello'

The go to localhost:3000/say/hello Also check out this documentation:

http://guides.rubyonrails.org/routing.html

u19964
  • 3,255
  • 4
  • 21
  • 28
  • it work, fine! but I don't understand if it's a task to run every time I create a controller? – mariobros Jun 19 '12 at 12:47
  • If you create a new method in controller and want to route to it, you have to define that in the config/routes.rb. – u19964 Jun 19 '12 at 12:53
  • Now i have Template Missing error: Missing template say/hello, application/hello with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/rails_proj/demo/app/views" – mariobros Jun 19 '12 at 13:07
  • This is how Model View Controller in Rails works. You have a controller Say with an action Hello, now you need a View Hello that is inside Say. The app looks into app/views/application/ or app/views/say/ for something like hello.html.erb to display on the web. Try creating such html file. – u19964 Jun 19 '12 at 13:12
0

I assume, controller: say and action: hello

Add following to config/route.rb

 get 'say/hello' => 'Say#hello'
Shamith c
  • 3,719
  • 3
  • 25
  • 33