brief update I might not even bother with a form to submit the data to the database and instead just use Heroku console, so my only concern is retrieving it.
www.un.org/spanish/ecosoc
我读到所有书本,但现在,我不想执行一米混淆。
我制作了一个名为“总”(不是最佳名称,而是又是一个问题)的模型,有三栏:<代码>的利润/代码>、<代码>编号代码>和<编码>。 页: 1
t = Total.first
=> #<Total id: 1, profit: 500, number: 7, fees: 40, created_at: "2012-01-12 04:21:33", updated_at: "2012-01-12 04:21:58">
(说明,我假定,这一条目将可到当地东道方:如果在发展数据库上公布,可上网查阅:3 000。)
我提供这一数据的最容易之处(由于我的网页布局)是application.html.erb
。 因此,我只字不提。 当你看上这个表格时,你可以看到,我如何通过在以下实例中点取利润来介绍数据:@t. ellit.
@t.fees。
<table class = "condensed-table" >
<thead>
<tr>
<th>Profit </th>
<th>Number of Trades</th>
<th> Fees</th>
</tr>
</thead>
<tbody>
<tr>
<td>$<%= @t.profit %> </td>
<td><%= @t.number %></td>
<td><%= @t.fees %></td>
</tr>
</tbody>
</table>
因此,现在,它只是一个从数据库中获取数据的问题,它造成了案例变量,因此我可以称之为`t.elli',就像我在奥索尔所做的那样。
ruby-1.9.2-p290 :019 > t.profit
=> 500
So with a Total.rb model
and presentation in application.html.erb
, I figured I needed to do this ....
@t = Total.find(params[:id])
to get the data from the database, but what should I call the method and where should i put it to make it work?
例如,如果我有网页控制器和页面浏览器,那么我就能够像像这样制定指数行动。
def index
@t = Total.find(params[:id])
end
and then I could just do @t.profit
(i assume). However, if I did something like that my table to present the data wouldn t be available on every part of my site.
我试图将其付诸实施——控制者。
def index
@t = Total.find(params[:id])
end
并且传递这一错误信息
NoMethodError in Posts#index
Showing /Users/me/Sites/enki2/app/views/layouts/application.html.erb where line #73 raised:
undefined method `profit for nil:NilClass
Extracted source (around line #73):