Hello All,
My question is this.
I’m trying to connect to a MySQL DB for read only in ROR
Class Report < ActiveRecord::Base
set_table_name “stories”
set_primary_key “record_id”
end
script/console
story = Report.find(56734) #Retrieve just a specific record_id Works
but I’m not able to iterate over this.
story.each { |fields| puts fields }
NoMethodError: undefined method each' for #<Editorial:0x4979ce0> from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ attribute_methods.rb:256:in
method_missing’
from (irb):226
from :0
So assuming there is another method that I can use to gather all or
selected fields?
If I reference each filed by name it works
story.record_id
story.file_name
I’m sure I’m missing something very basic here.
Thanks Sc
On Jun 18, 6:51 pm, scottc12 [email protected] wrote:
So assuming there is another method that I can use to gather all or
selected fields?
If you want to iterate over all attributes, look at story.attributes.
Fred
On Jun 18, 2008, at 1:51 PM, scottc12 wrote:
from :0
Report.find(56734) will return a single Report object
Report.find([56734]) will return an array containing a single Report
object.
Is that the iteration that you want?
So assuming there is another method that I can use to gather all or
selected fields?
If I reference each filed by name it works
story.record_id
story.file_name
I’m sure I’m missing something very basic here.
Thanks Sc
Otherwise, if you want the fields or attributes of a single Report
(one row from stories and its columns), then Fred has already given
you the hint.
-Rob
Rob B. http://agileconsultingllc.com
[email protected]
Hello All,
Thanks so much this has put me on the correct track. I was not sure
how to get things into an array which this solves. I suppose I could
also do a Stories.find(:all) and which returns and array.
Thanks everyone …
sc
On Jun 18, 3:30 pm, Rob B. [email protected]