Hi
On Sat, Jun 4, 2016, at 04:16, Rynn Steinbolt wrote:
> Hello Folks!
>
> Im stuck with my current task, partly because there seems to be a lack
> of basic understanding of syntax i cant pinpoint. I hope you can show me
> a way out!
>
> What Im trying to do is processing one model's data, thus turning it
> into another model's data. It works with one datum, but I cant get it to
> work with the whole data set. I tried several versions of code in
> several places, but this is the current version:
>
> class RawDatum < ActiveRecord::Base
> default_scope :order => 'raw_data.timestamp DESC'
> def self.process_raw_data
> i = 0
> RawDatum.find_each do |raw|
> data[i] = ProcessedDatum.create
> data[i].period_label = raw.status
> i += 1
> end
> return data
> end
> end
>
You need to initialize data variable before doing the loop (`data =
[]`).
def self.process_raw_data
data = []
find_each do |raw|
data << ProcessedDatum.create(period_label: raw.status)
end
data
end
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1464982249.844296.627323489.1FE69A85%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment