How do I give a Ruby script executed via Rails console write permissions on Digital Ocean?

462 views Asked by At

I am deploying my Rails app to Digital Ocean.

I need to run a custom ruby script via the Rails console (or even on a job queue) and in some cases I want it to create a file and store it within my config directory.

Specifically, this is what the setup looks like:

Money.default_bank = MoneyOXR::Bank.new(
  app_id: ENV["APP_ID"],
  cache_path: 'config/oxr.json',
  max_age: 86400
)

So, what needs to happen is whenever it runs it needs to create the config/oxr.json.

However, when I run it, this is what happens:

Errno::EACCES: Permission denied @ rb_sysopen - config/oxr.json

Right now, I am just running it as MyScript.run at the command line in Rails console.

How do I do this?

1

There are 1 answers

0
uday On BEST ANSWER

You need to give the necessary folder permissions to create/write a file. You can do that by:

chmod -R g+w app_path/config

This gives write permission to app config folder.

If you want to give permissions to a certain user then:

=> w || who; #list all of the currently logged in users
=> chgrp -R user_name app_path/config
=> chmod -R g+w app_path/config

Edited by OP

What also works is: sudo chmod 777 oxr.json