Reputation: 355
I have an application in ruby, that I want to make some configurations. For example, in development, I want that a user can add only 10 photos on an albun for a certain plan.
Something like this:
development:
number_photos:10
production:
number_photos:30
And want to acess those values on my controllers. For example. On my photos_controller.rb
def get_number_photos
#how can I read the value of the number_photos of the configuration file?
end
What is the better way to do something like this?
Upvotes: 0
Views: 57
Reputation: 120990
Create the .config.yaml
(name is arbitrary) file in Rails.root
and fill it with your content.
development:
number_photos: 10
production:
number_photos: 30
In your controller do:
yaml_config =
YAML.load_file(Rails.root.join('.config.yaml'))
number_photos = yaml_config[Rails.env]['number_photos']
It’ll set the number according to your current environment setting.
Upvotes: 1