Hi, Im trying to make an application based on the ''depot'' app from ''Agile web development with Rails''. Instead of putting the data in add_test_data.rb itself (p.89), I want to read it in from a txt file like this (gg.txt has a list of front and last names): class AddTestData < ActiveRecord::Migration def process(k) k.chop! ary = k.split Zwemmer.create(:lastname => ary[1,3].join('' ''), :frontname => ary[0].to_s.downcase, :group => ''gg'', :image_url => ''/images/ggs.png'') end def self.up Zwemmer.delete_all myfile =File.new("gg.txt", "r") myfile.each {|line| process(line)} myfile.close end def self.down end end error: rake aborted! No such file or directory - gg.txt gg.txt is in the same directory as add_test_data.rb. Where should i put the txt file? How should i read it in? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 6, 5:18 pm, Kelly Pfaff <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > Im trying to make an application based on the ''depot'' app from ''Agile > web development with Rails''. Instead of putting the data in > add_test_data.rb itself (p.89), I want to read it in from a txt file > like this (gg.txt has a list of front and last names): > > class AddTestData < ActiveRecord::Migration > def process(k) > k.chop! > ary = k.split > Zwemmer.create(:lastname => ary[1,3].join('' ''), :frontname => > ary[0].to_s.downcase, :group => ''gg'', :image_url => ''/images/ggs.png'') > end > > def self.up > Zwemmer.delete_all > myfile =File.new("gg.txt", "r") > myfile.each {|line| process(line)} > myfile.close > end > > def self.down > end > end > > error: > rake aborted! > No such file or directory - gg.txt > > gg.txt is in the same directory as add_test_data.rb. Where should i put > the txt file? How should i read it in?Rake sets the work directory to the root of the rails app. You''re also trying to call an instance method from a class method, which won''t work. Fred> > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Thanks for the speedy reply Fred. I''ve relocated gg.txt to the right directory, and now a new error pops up, as you have foreseen: Undefined method ''process'' ... What can i do to solve this? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Kelly Pfaff wrote in post #979916:> Thanks for the speedy reply Fred. > I''ve relocated gg.txt to the right directory, and now a new error pops > up, as you have foreseen: > Undefined method ''process'' ... > > What can i do to solve this?I made process a class method too, now it works.. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.