Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load a file from the config folder?

I'm trying to use the evernote gem to access the Evernote API. In those instructions, it says to create a config file containing the API account details, and then load the config file as follows:

config = File.dirname(__FILE__) + "/config.yml"
user_store = Evernote::UserStore.new(user_store_url, config, "sandbox")

I created a file evernote.yml in the config folder, and put the following code in the home action in pages_controller.rb

config = File.dirname(__FILE__) + "/evernote.yml"
user_store = Evernote::UserStore.new(user_store_url, config, "sandbox")

When the code is run, I get this error on the 2nd line

Errno::ENOENT in PagesController#home
No such file or directory - /Users/ben/rails_projects/evernote_app/app/controllers/evernote.yml

How do I load the config file without getting this error?

like image 853
ben Avatar asked Feb 14 '11 05:02

ben


People also ask

How do I load a config file?

To load Configs, select the configurations you want to load and click Load. To load multiple instances of one Config, select the config you want to load and click Load As.... The Custom Load window opens, allowing you to specify Config File, Config Run name, Config Password, and Property Store Value.

What does the config folder do?

In computing, configuration files (commonly known simply as config files) are files used to configure the parameters and initial settings for some computer programs. They are used for user applications, server processes and operating system settings.

Where do config files go?

There are thousands of configuration files on your computer. You may never directly interact with the bulk of them, but they're scattered throughout your /etc folder and in ~/. config and ~/. local and /usr .

How do I open and edit a config file?

Windows Config Files Windows users will find the hosts file in c:\windows\system32\drivers\etc\. You can open it by double-clicking the mouse and selecting Notepad from the list of suggested apps. This is all you need to view and edit config files like hosts.


1 Answers

If you are using Rails, since 4.2 there's a builtin way to do that:

config = Rails.application.config_for(:evernote)

Source: https://www.justinweiss.com/articles/the-lesser-known-features-in-rails-4-dot-2

like image 132
Adrien Jarthon Avatar answered Oct 12 '22 12:10

Adrien Jarthon