Skip to content

Instantly share code, notes, and snippets.

@brylor
Created February 11, 2015 21:32
Show Gist options
  • Save brylor/6a1473324ecf878e7e12 to your computer and use it in GitHub Desktop.
Save brylor/6a1473324ecf878e7e12 to your computer and use it in GitHub Desktop.
self.reports.each_with_index do |i, r|
if i == 0
r.amount = 5000
r.save
else
r.amount = r.amount + @total
r.save
end
end
NoMethodError (undefined method `amount' for 0:Fixnum):
app/models/projection.rb:28:in `block in update'
app/models/projection.rb:23:in `update'
app/controllers/projections_controller.rb:45:in `block in update'
app/controllers/projections_controller.rb:44:in `update'
irb(main):075:0> @projection.reports.each_with_index do |i,r|
irb(main):076:1* puts i
irb(main):077:1> puts r
irb(main):078:1> end
Report Load (0.2ms) SELECT "reports".* FROM "reports" WHERE "reports"."projection_id" = ? [["projection_id", 1]]
#<Report:0x007fa4964d9e18>
0
#<Report:0x007fa4965892c8>
1
#<Report:0x007fa496589048>
2
#<Report:0x007fa496588da0>
3
#<Report:0x007fa496588b48>
4
#<Report:0x007fa4965888c8>
5
#<Report:0x007fa4965885f8>
6
#<Report:0x007fa496588378>
7
#<Report:0x007fa4965880a8>
8
#<Report:0x007fa4964ebf50>
9
#<Report:0x007fa4964ebcf8>
10
#<Report:0x007fa4964eba78>
11
#<Report:0x007fa4964eb7a8>
12
#<Report:0x007fa4964eb550>
13
=> [#<Report id: 2, projection_id: 1, amount: 2400, created_at: "2015-02-09 14:45:24", updated_at: "2015-02-11 21:17:00">, #<Report id: 3, projection_id: 1, amount: 2400, created_at: "2015-02-09 14:56:21", updated_at: "2015-02-11 21:17:02">, #<Report id: 4, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:02">, #<Report id: 5, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:02">, #<Report id: 6, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:02">, #<Report id: 7, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:02">, #<Report id: 8, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:02">, #<Report id: 9, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:02">, #<Report id: 10, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:02">, #<Report id: 11, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:02">, #<Report id: 12, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:03">, #<Report id: 13, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:03">, #<Report id: 14, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:03">, #<Report id: 15, projection_id: 1, amount: 2400, created_at: "2015-02-09 16:41:04", updated_at: "2015-02-11 21:17:03">]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment