Manage all project environment variables at one place using Gem Figaro
Basically a Rails project in Framgia, when you start you have to do the following: 1. Engine
2. Workflow if NOT using Figaro
rails new
database.yml
to .gitignore
, then duplicate this file to create fie template database.yml.example
rake secret
create a key, please pity into the config
folder to create secrets.yml.template
(yes, template), duplicate this file to create the secrets.yml
file, fill in the required information. Set it and then put this file in .gitignore
to hide it. 3. Workflow if using Figaro
figaro
to Gemfileapplication.yml
has been created for you and this file is automatically added to the .gitignore
. Due to the standard yml, the addition of key and value fields is very familiar, in addition to the calling method can not be simpler than ENV["{tên_key}"]
or Figaro.env.{tên_key}
. Enddatabase.yml
, secrets.yml
, application.yml.example
that you standardize to use in all projects from now on. .
For example:
- database.yml1234567891011121314common: & amp; commonadapter: mysql2encoding: utf8mb4collation: utf8mb4_binusername: & lt;% = Figaro.env.database_username% & gt;password: & lt;% = Figaro.env.database_password% & gt;reconnect: & lt;% = Figaro.env.database_reconnect% & gt;pool: & lt;% = Figaro.env.database_pool% & gt;host: & lt;% = Figaro.env.database_host% & gt;database: & lt;% = Figaro.env.database_name% & gt;development:& lt; & lt ;: * commonproduction:& lt; & lt ;: * common
- secrets.yml123456common: & amp; commonsecret_key_base: & lt;% = Figaro.env.secret_key_base% & gt;development:& lt; & lt ;: * commonproduction:& lt; & lt ;: * common
- application.yml.example1secret_key_base: database_username: database_password: database_reconnect: database_host: database_pool: database_name: mail_username: mail_password: production: secret_key_base: devise_key_base: database_username: database_password: database_reconnect: database_host: database_pool: database_name: mail_username: mail_password:
config
folder (the file application.yml.example – will help other teammates easily set up the project environment variable)application.yml
file according to the format of application.yml.example
.4. Conclusion
According to the Convention over configuration
concept of Rails, standardizing and helping dev not lose in thinking and making many decisions (without reducing the flexibility of the project) is my idea when deciding to come to Figaro. By using Figaro, it will help you start a project easily and help it take less time, standardize projects as well as the most important thing is to have an effective management place to help you not worry. Thinking about managing important variable information in the project according to the environment. This is just an idea presentation and hope you have some interest in Figaro, more details you can see on Github's gem.
5. Problems encountered
This is just a small problem, but I have encountered it when using Rubymine. Rubymine integrates the database connection of your IDE project, based on database.yml
file to login to the db always. However, I have added these parameters to application.yml
so I have a login error. May the Rubymine talents correct soon.
Thank you for watching the article