user5693914
user5693914

Reputation:

Rails load yml file in application

I have made a yml file and placed in config/locals/models/en-US.yml .But I don't know how to load that file and get the data from that file to a view

en-US.yml

en-US:
  mysqlid:
    models:
      dashboard:
        one: Dashboard
        other: Dashboards
    attributes:
     dashboard:
        email: Email
        name: Name
        facebook_verified: Verified on Faceboo

Upvotes: 1

Views: 3410

Answers (2)

x6iae
x6iae

Reputation: 4164

To get your yml data, you will need to use the YAML class to load the file.

To do this, you have to require yaml and then use it to load the data like below:

#controller:
require 'yaml'

def method
  @yaml_data = YAML.load_file('config/locales/models/en-US.yml ')
end

and the yaml data will be loaded into the @yaml_data instance variable, which you can now access from your view.

Upvotes: 1

Alexander Shlenchack
Alexander Shlenchack

Reputation: 3869

Add this to your config/application.rb file:

config.i18n.load_path += 
  Dir[Rails.root.join('config', 'locales', '**/*.{rb,yml}').to_s]

More info there: http://guides.rubyonrails.org/i18n.html

Upvotes: 2

Related Questions