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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 18, 6:51 pm, scottc12 <scomb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> > 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 18, 2008, at 1:51 PM, scottc12 wrote:> 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 :0Report.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 ScOtherwise, 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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Jun 18, 2008, at 1:51 PM, scottc12 wrote: > > > > > 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 > > 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 Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---