ruby on rails - Unable to read file from within rake task -


i have rake task reads file.

desc "dump images." task :dump_with_images => :environment   yaml_path = rails.root + 'db/data.yml'    # output: "" -- empty string   puts file.open(yaml_path).read.inspect   [...] end end 

if read , inspect file outside of task,

yaml_path = rails.root + 'db/data.yml' puts file.open(yaml_path).read.inspect  desc "dump images." task :dump_with_images => :environment 

it gives me data:

zeromodulus@kosuna:~/projects/recipes$ rake dump_with_images "\n---\nphotos:\n  columns:\n  - id\n  - created_at\n  - updated_at\n  - recipe_id\n  - image_file_name\ 

i don't understand why can read exact same file outside of task, not in task.

when inspect yaml_path, they're both same, , file has data in it.

it looks opening file stream , not closing it, , later on in code attempting open same file stream again.

i've wrapped file reading code in block,

file.read(file_path, "r") |f|   yaml.load_stream(f) end 

which has solved problem.

update:

the problem has resurfaced, though have opened/closed file streams properly. problem lies elsewhere, couldn't figure out, decided abandoned yaml_db , use standard db/seeds.rb


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -