简体   繁体   中英

Ruby On Rails and Heroku issue when writing in yaml files

i'm working on rails and deploying my app on heroku.

I have build a translation system and in this system i need to write in yaml files

here is how i proceed :

File.open(ENV['PATH_TO_FILE'], 'w') do |f|
    f.write hash.to_yaml
  end

In localhost, it works perfectly, in the rails console, when i do

YAML::load_file(ENV['PATH_TO_FILE'])

i can see the new keys that have been added.

However, after deploying on Heroku, and running the same code in the rails console of heroku, no keys are added.

Does anyone have a solution to this problem?

Thanks in advance,

Heroku is a read-only file system , so writing to the yaml file won't be possible.

I would explore using a key/value store like redis or similar in place of the yaml file.

If you're on Bamboo stack, Heroku's filesystem is read only .

If you're on Cedar, each dyno has its own ephemeral filesystem. Check out this section of the Heroku docs

It's also possible the environment variable PATH_TO_FILE is not set correctly on heroku. I recommend using the Figaro gem to manage your environment variables https://github.com/laserlemon/figaro

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM