1

My first doubt is what is the difference between yml and yaml. Which one I should use. Also I have to put my label in yml file and to load them. So I don't have any idea how to do that. Any example or tutorial for that will be very helpful.

Tomasz Jakub Rup
  • 9,464
  • 7
  • 44
  • 47

2 Answers2

1

'yml' is the extension you would use for 'YAML' files, so there's no difference between them.

Loading a YAML file in Ruby is as simple as YAML.load_file( <filename> ): it will read the whole file as a normal Hash. To convert back to yaml use the homonymous method to_yaml.

You can get started here or here

Claudio Floreani
  • 2,099
  • 25
  • 33
  • How to load those files in my rails application .If i have a yml file so how to load data in my view from there –  Dec 18 '15 at 12:22
1

Setting Rails environment variables. Using ENV variables in Rails, locally and with Heroku. Rails configuration and security with environment variables.

Environment Variables

Many applications require configuration of settings such as email account credentials or API keys for external services. You can pass local configuration settings to an application using environment variables.

Operating systems (Linux, Mac OS X, Windows) provide mechanisms to set local environment variables, as does Heroku and other deployment platforms. Here we show how to set local environment variables in the Unix shell. We also show two alternatives to set environment variables in your application without the Unix shell.

Gmail Example

config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "example.com",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
}

You could “hardcode” your Gmail username and password into the file but that would expose it to everyone who has access to your git repository. Instead use the Ruby variable ENV["GMAIL_USERNAME"] to obtain an environment variable. The variable can be used anywhere in a Rails application. Ruby will replace ENV["GMAIL_USERNAME"] with an environment variable.

Option One: Set Unix Environment Variables

export GMAIL_USERNAME="myname@gmail.com"

Option Two: Use the Figaro Gem

  • This gives you the convenience of using the same variables in code whether they are set by the Unix shell or the figaro gem’s config/application.yml. Variables in the config/application.yml file will override environment variables set in the Unix shell.
  • Use this syntax for setting different credentials in development, test, or production environments:

**

HELLO: world
development:
  HELLO: developers
production:
  HELLO: users

**

In this case, ENV["HELLO"] will produce “developers” in development, “users” in production and “world” otherwise.

Option Three: Use a local_env.yml File

Create a file config/local_env.yml:

Hope this help your answer!!!

Gupta
  • 5,122
  • 3
  • 27
  • 46