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

class ProcessedDatum < ActiveRecord::Base
end

class ProcessedDataController < ApplicationController
   def index
     @data = RawDatum.process_raw_data
   end
end

when i open localhost:3000/processed_data/, i get the following error:
undefined local variable or method `data' for #<Class:0x9c785f4>
app/models/raw_datum.rb:11:in `block in process_raw_data'
app/models/raw_datum.rb:10:in `process_raw_data'
app/controllers/processed_data_controller.rb:9:in `index'

the data variable is supposed to be an array that should hold
ProcessedDatum-objects, its just a container variable. it seems i have
to define it, but how would I do that? am i doing this entirely wrong,
and if so, what would be a better way?

--
Posted via http://www.ruby-forum.com/.

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/21ff9b4b1039056a2b86cb5a4d2cb332%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 6 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJun 3, '16 at 7:16p
activeJun 3, '16 at 7:49p
posts6
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2023 Grokbase