ROR学习系列24-Rails基础7-数据交互之models

1 创建工程modeler
2 创建控制器Look
3 在modeler\app\models下创建cruncher.rb
代码为:
class Cruncher
def crunch
return 5
end
end

4 修改刚才在modeler\app\controllers下创建的look_controler.rb,代码如下:
class LookController < ApplicationController
def at
@cruncher = Cruncher.new
@data = @cruncher.crunch
end
end

5 在modeler\app\views\look下创建at.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>

6 在页面上输出的结果为The fetched data is: 5.

你可能感兴趣的:(html,Ruby,Rails)