Showing posts with label YAML. Show all posts
Showing posts with label YAML. Show all posts

Friday, 1 June 2012

YAML file configuration in rails application

Hi,

We may required to configure some things in rails application in configuration level. So these things can be configured in YAML file as below.


1) Create your configuration file in config/myconfig.yml

common: &default_settings
  user_settings:
    email: yes
    profile: yes
  product:
    price: yes
    image: yes

development:
  <<: *default_settings


staging:
  <<: *default_settings


production:
  <<: *default_settings


test:
  <<: *default_settings


2) It should be initialised in config/initializers/load_config.rb

APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/myconfig.yml")[RAILS_ENV]


3) You can access those setting any where in the application
 
   APP_CONFIG['user_settings']['email']

I came to see there is one more useful gem which can do these functionality.  Here is it YETTINGS https://github.com/charlotte-ruby/yettings


Thank You,
Uma Mahesh

couldn't parse YAML at line (Psych::SyntaxError)

I have used YML file for configuring globally few things for the application.

I have alligned the yml file with correct structure and correct indentation. Stil it trows the following error

  couldn't parse YAML at line (Psych::SyntaxError)

There is a tool YAML Lint http://www.yamllint.com/ helped me to check the yml allignment that I have coded was correct or wrong

Just copy and past your code in that site and click go It will Display the error line if you have any error's.

Thank You,
Uma Mahesh.