I''m sure this is going to be a very silly question but can anyone tell me why this code is giving me errors? require ''rubygems'' require ''mysql'' db = Mysql.new(''localhost'', ''root'', ''avuzritfanu'', ''studentevents'') begin results = db.query "SELECT * FROM events_event" puts "Number of users #{results.num_rows}" results.each_hash do |row| event = { :title=>row["title"], row["start_time"] = "09:00:00" if row["start_time"].nil? row["end_time"] = "17:00:00" if row["end_time"].nil? :startTime=>row["start_time"], :endTime=>row["end_time"]} puts "Title of event #{row["start_time"]} " end results.free ensure db.close end Here''s the errors mysqlconnect.rb:10: syntax error, unexpected kIF_MOD, expecting tASSOC row["start_time"] = "09:00:00" if row["start_time"].nil? ^ mysqlconnect.rb:12: syntax error, unexpected tASSOC, expecting kEND :startTime=>row["start_time"], ^ mysqlconnect.rb:13: syntax error, unexpected tASSOC, expecting tCOLON2 or ''['' or ''.'' :endTime=>row["end_time"]} ^ mysqlconnect.rb:13: syntax error, unexpected ''}'', expecting kEND --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi -- On Tue, 29 Apr 2008, vanderkerkoff wrote:> > I''m sure this is going to be a very silly question but can anyone > tell > me why this code is giving me errors? > > require ''rubygems'' > require ''mysql'' > db = Mysql.new(''localhost'', ''root'', ''avuzritfanu'', ''studentevents'') > begin > results = db.query "SELECT * FROM events_event" > puts "Number of users #{results.num_rows}" > > results.each_hash do |row|I''m re-ordering your lines, to take the row assignments out of the literal hash:> row["start_time"] = "09:00:00" if row["start_time"].nil? > row["end_time"] = "17:00:00" if row["end_time"].nil? > event = { :title=>row["title"], > :startTime=>row["start_time"], > :endTime=>row["end_time"]} > puts "Title of event #{row["start_time"]} "Are you sure you don''t mean row["title"] there? Also, why are you creating the event hash at all? You don''t seem to use it.> endDavid -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
opening an hash assignment: event = { :title=>row["title"], within this hash do this: (? can''t work that way ?) row["start_time"] = "09:00:00" if row["start_time"].nil? row["end_time"] = "17:00:00" if row["end_time"].nil? and go on with hash keys: :startTime=>row["start_time"], :endTime=>row["end_time"]} and close it. if those two lines with row[...] are not very tricky and i miss this, then it''s wrong. they should be otside the hash or would have to look different if their result should somehow become part of this hash. -- 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 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 -~----------~----~----~----~------~----~------~--~---
Hi David It''s just a snippet of the entire code, the events hash will eventually be used to populate a google calendar. Hopefully :-) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---