escargot agile
escargot agile

Reputation: 22379

Accessing files from Rails initialization code

I'm trying to use the gtfs library. There's some long-running code that needs to be run on initialization (it needs to unzip a 118MB zip file):

source = GTFS::Source.build(<URI or Path to GTFS zip file>)

I tried to put the zip file in /public and then access it from appplication.rb:

config.after_initialize do
    puts "building GTFS"
    source = GTFS::Source.build("http://localhost:3000/gtfs-2014-02-14.zip")
    puts "built GTFS"
    source.each_agency {|agency| puts agency}
end

However, I got this error:

/home/myuser/.rvm/gems/ruby-2.1.0/gems/gtfs-0.2.2/lib/gtfs/url_source.rb:18:in `rescue in load_archive': Connection refused - connect(2) for "localhost" port 3000 (GTFS::InvalidSourceException)

Am I right in putting this initialization in application.rb? And how can I access files from there?

Upvotes: 1

Views: 77

Answers (1)

rainkinz
rainkinz

Reputation: 10394

Your application won't be accepting requests while initializing. Does this work?

source = GTFS::Source.build("#{Rails.root}/public/gtfs-2014-02-14.zip")

Upvotes: 1

Related Questions