English 中文(简体)
铁路网:从数据库获取价值,并在应用上显示。
原标题:Rails noob: getting value from database and showing on application.html.erb

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):
最佳回答
问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签