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?
On Feb 6, 5:18pm, Kelly P. [email protected] wrote:
Zwemmer.create(:lastname => ary[1,3].join(’ '), :frontname =>
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
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?
Kelly P. 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…