File: app\models\cruncher.rb
class Cruncher
def crunch
return 5
end
end
File: app\controllers\hello_controller.rb
class HelloController < ApplicationController
def there
@cruncher = Cruncher.new
@data = @cruncher.crunch
end
end
File: app\views\hello\there.rhtml:
<html>
<head>
<title>Using Models</title>
</head>
<body>
<h1>Working With Models</h1>
This application fetches data from a model.
<br>
<br>
The fetched data is: <%= @data %>.
<br>
<br>
</body>
</html>
Start the WEBrick server: ruby script/server
Navigate to http://localhost:3000/hello/there
|