skip to Main Content

I’m trying to host an app in plesk server. I created a custom variable as in the printscreen:
enter image description here

I want to access this variable in seed.rb file so that I could create a user with password through rake db:seed.

Is this the correct approach? Is there a better and safer way to create the admin user with sensitive data (password)? Please point a tutorial if you can.

Edit:
I’ll provide some more info

I use this seeds.rb file:

case Rails.env
when "development"
puts "Seeding: development mode!"
...
when "production"
puts "Seeding: production mode!"
puts "ENV: #{ENV['admin_pass']}"
end
puts "Seeding finished!"

and when i use the run rake task command that plesk provides i get this result:
Rake db:seed result

EDIT #2: Some solution!

when I provide the variable in task parameters It works!!! But what happens if I want to declare much more environment variables this way?
some solution

2

Answers


  1. I agree with your concern on solution 2. Another problem that solution is that you can’t share environment variables for others application processes, such as: rails console or rails server.

    Another solution is to use figaro to manage environment variables.

    1. Add figaro to Gemfile
    2. Create application.yml contains key-value configurations and upload to config folder.

    —— config/application.yml ——

    production:
      admin_pass: hello
    

    Then try to run rake db:seed task again.

    Login or Signup to reply.
  2. There is a feature suggestion regarding this issue:

    Pass variables specifed in Ruby menu in field "Custom environment variables" to rake tasks

    Currently, the option "Custom environment variables" in the menu "Ruby" on a domain is used only for passing environment variables to the application. But it’s also required to pass environment variables to the rake tasks as well, and in the current implementation, it’s necessary to specify necessary variables in the window "Run rake task" each time a rake tasks needs to be executed.
    Variables specifed in the option "Custom environment variables" should be passed to rake tasks as well, as similar options work this way in other products known for developers and used for hosting Ruby apps like Heroku and DigitalOcean.

    You can vote for it here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search