1. Engine
- I am currently participating in a Rails project and feel very excited to learn and learn new knowledge after a long time without touching.
- Due to the fact that over the past year has not directly touched the code, I pay more attention to the techniques to make the project start and happen in a smoother and smoother way.
- A project Rails always has a lot of information that needs to be hidden at the local and not to let outsiders know, how to manage it effectively is something I have to worry about until I know about Gem Figaro .
- Using Figaro gem can help you standardize all participating projects easily
2. Workflow if NOT using Figaro
Basically a Rails project in Framgia, when you start you have to do the following:
- Create a Rails project with
rails new
- Add
database.yml
to.gitignore
, then duplicate this file to create fie templatedatabase.yml.example
- Since it is necessary to have a secret key for the Rails app, after using
rake secret
create a key, please pity into theconfig
folder to createsecrets.yml.template
(yes, template), duplicate this file to create thesecrets.yml
file, fill in the required information. Set it and then put this file in.gitignore
to hide it. - In addition, there are many other environment variables like secret key for devise, information about email account will be used to shoot mail …
3. Workflow if using Figaro
- Check out the documentation about gem Figaro. Using:
- add
figaro
to Gemfile - bundle install
- bundle exec figaro install
- Yes, it is simple in 3 basic steps, 1 file named
application.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 thanENV["{tên_key}"]
orFigaro.env.{tên_key}
. End
- add
- If this is the first time, please create any folder, which will contain the
database.yml
,secrets.yml
,application.yml.example
that you standardize to use in all projects from now on. .
For example:- database.yml
1234567891011121314common: & 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.yml
123456common: & amp; commonsecret_key_base: & lt;% = Figaro.env.secret_key_base% & gt;development:& lt; & lt ;: * commonproduction:& lt; & lt ;: * common
- application.yml.example
1secret_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:
- database.yml
- Copy the three files into the project
config
folder (the file application.yml.example – will help other teammates easily set up the project environment variable) - Fill in the required information into the
application.yml
file according to the format ofapplication.yml.example
. - Everything is ready for you.
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