나는 약간의 일을하고 있습니다. 여기서는 마이그레이션을 통해 데이터베이스를 채우고 텍스트 파일의 내용을 사용하고 있습니다. 이레일스 ActiveRecord :: Migration - 데이터베이스에 텍스트 파일 내용 쓰기
class AddChapters < ActiveRecord::Migration
def self.up
Chapter.create!(:title => "chapter 1",
:body => File.open("#{Rails.root}/chapters/chapter1.txt").gets)
Chapter.create!(:title => "Chapter 2",
:body => File.open("#{Rails.root}/chapters/chapter2.txt").gets)
Chapter.create!(:title => "Chapter 3",
:body => File.open("#{Rails.root}/chapters/chapter3.txt").gets)
end
def self.down Chapter.all.each do |chapter| chapter.delete end end end
많이 감사합니다. IO.read가 트릭을했습니다 ... .txt를 사용하고 seed/fixtures를 사용하지 않는 이유는 사용자가 .txt 파일을 쓰려고 할 때 (루비 파일이 아닌) 편집하려고하기 때문입니다. –