:031:0> @revenue = Revenue.where(:Year=>1983)
←[1m←[36mRevenue Load (1.0ms)←[0m ←[1mSELECT "revenues".* FROM "revenues" WHERE "revenues"."Year" = 1983←[0m
=> [#<Revenue id: 9, Year: 1983, Amount: 4.0, Q1: 1.0, Q2: 1.0, Q3: 1.0, Q4: 1.0
, created_at: "2013-06-11 16:41:16", updated_at: "2013-06-11 16:41:16", estate_i
d: 1>]
irb(main):032:0> @revenues.Amount
NoMethodError: undefined method `Amount' for nil:NilClass
from (irb):32
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/commands/console.rb:47:in `start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/commands/console.rb:8:in `start'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.1
3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
irb(main):033:0>
答案 0 :(得分:1)
因为您的收入对象位于@revenue,而您正在尝试@ revenue.Amount
所以试试@revenue.amount