I have just started looking at Ruby on Rails and am following a book
‘Beginning Ruby on Rails’.
The first exercise is to display a webpage but when entering the url in
Firefox it doesnt display.
I get this error message:
Page title:
Action Controller: Exception caught
Page body:
Routing Error
no route found to match “/app/greeting” with {:method=>:get}
All I did was add these lines:
def greeting
end
to application.rb so it now looks like:
Filters added to this controller apply to all controllers in the
application.
Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
Pick a unique cookie name to distinguish our session data from
others’
session :session_key => ‘_hello_session_id’
def greeting
end
end
Any ideas?
Thanks.
Joe 3000 wrote:
I have just started looking at Ruby on Rails and am following a book
‘Beginning Ruby on Rails’.
The first exercise is to display a webpage but when entering the url in
Firefox it doesnt display.
I get this error message:
Page title:
Action Controller: Exception caught
Page body:
Routing Error
no route found to match “/app/greeting” with {:method=>:get}
All I did was add these lines:
def greeting
end
to application.rb so it now looks like:
Filters added to this controller apply to all controllers in the
application.
Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
Pick a unique cookie name to distinguish our session data from
others’
session :session_key => ‘_hello_session_id’
def greeting
end
end
Any ideas?
Thanks.
I’ve never seen that book, but as far as I know the “application.rb”
file is not meant to be used that way. What you need to do is generate a
new controller and put “def greeting” in there. For example in the
console/command line type:
/script/generate controller test
That should create a file called “test_controller.rb”. Open that file
and put “def greeting” in there. The URL will then be “/test/greeting”.
Of course, you also need to create a view for greeting called
“greeting.rhtml” that conatins some HTML, or you need to render text
directly in the controller.
Anyway, I don’t want to get into a major rails tutorial. I mainly wanted
to point out the usual way to start up a rails application. Sounds like
that book may be a bit too complicated for the basics or you’re not
following it correctly. I recommend you look at the following very, very
simple and well written A-Z tutorial:
Joe 3000 wrote:
Routing Error
no route found to match “/app/greeting” with {:method=>:get}
By default, the URL for /app/greeting will look for an app controller
with method greeting. Since you do not have an app_controller, it
failed.
Btw, ApplicationController should be used as a base class, not as a
concrete class.