I'm writting a ruby gem and I want to let user use your own yaml file configuration, but I don't know how to test if the user_config.yml exists into rails config path.
I want to use user_config.yml only if this file exists into config path.
You probably know that you can configure Rails in config/application. rb and config/environments/development. rb etc. But you can also leverage that for configuring your own custom settings for your application.
The configuration file config/application. rb and environment-specific configuration files (such as config/environments/production. rb ) allow you to specify the various settings that you want to pass down to all of the components. Rails will use that particular setting to configure Active Record.
An initializer is any file of ruby code stored under /config/initializers in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks and plugins are loaded.
In Rails 2.3 Rails. root is an instance of Pathname where RAILS_ROOT is a string.
Rails.root
(or RAILS_ROOT
in earlier versions of Rails) gives you the path of the application root. From there, you can see if the file you're interested in exists.
e.g.
path = File.join(Rails.root, "config", "user_config.yml")
if File.exists?(path)
# do something
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With