Ruby on rails 3.2 Rails应用程序中的.txt文件保存在哪里?

Ruby on rails 3.2 Rails应用程序中的.txt文件保存在哪里?,ruby-on-rails-3.2,Ruby On Rails 3.2,我的rails应用程序中有一个模型“Geo”,如下所示。 在Rails应用程序中,text.txt文件保存在何处,在特定的代码行文件中调用什么地址。打开(“/india/text.txt”) 注意:text.txt是包含txt文件的数据 class Geo < ActiveRecord::Base attr_accessible :country_iso2, :country_name, :district, :latitude, :locality, :longitude,

我的rails应用程序中有一个模型“Geo”,如下所示。 在Rails应用程序中,text.txt文件保存在何处,在特定的代码行文件中调用什么地址。打开(“
/india/text.txt
”)

注意:text.txt是包含txt文件的数据

 class Geo < ActiveRecord::Base
      attr_accessible :country_iso2, :country_name, :district, :latitude, :locality, :longitude, :state_iso2, :state_name, :street, :taluka, :zip

    def self.create_or_save(locality_s, zip_s, state_s, district_s)
        g = Geo.where(zip: zip_s).first
        g = Geo.new(zip: zip_s) if g.blank?
        g.locality = locality_s
        g.state_name = state_s
        g.district = district_s
        g.save
    end

    def self.mine
        File.open("/india/text.txt") do |f|
            f.each_line do |line|
                li = line.split(":")
                    locality = li[0].to_s.strip
                    zip = li[1].to_s.strip
                    state = li[2].to_s.strip
                    district = li[3].to_s.strip
                Geo.create_or_save(locality, zip, state, district)
            end 
        end
    end
end
class-Geo
我想您应该使用
Rails.root

Rails.root.join('app', 'assets', 'txt', 'india', 'text.txt')

哪个映射到/app/assets/txt/india/text.txt

为什么不使用数据库呢?实际上,我用它从txt文件中获取日期并保存到数据库。您可以将数据文件公开/data/。。。。。但是如果说/india/file.txt,它将在主机的根目录中搜索目录'india'