I’m trying to host an app in plesk server. I created a custom variable as in the printscreen:
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:
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?
2
Answers
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.figaro
to Gemfile—— config/application.yml ——
Then try to run
rake db:seed
task again.There is a feature suggestion regarding this issue:
Pass variables specifed in Ruby menu in field "Custom environment variables" to rake tasks
You can vote for it here