This is assignment but how do you access this value then? If you look in the application. There is plenty of documentation on how to access the variable edgeguides.
Jack Pratt you could edit a more complete answer? Beware that if you set something only in production, and try to access it in another environment, it would complain undefined method. Show 14 more comments. Update 1 Very recommended: I'm going with Rails Config gem nowadays for the fine grained control it provides.
Update2 If you want a quick solution, then check Jack Pratt's answer below. Community Bot 1 1 1 silver badge. This answer is out-dated. See stackoverflow. Thanks for pointing out the outdated. I hate that about Rails -- code from 1 year ago is too old. In the documentation they instruct me to register RailsConfig in my app. I assume that app.
But where in the application. In Rails 3. Rory O'Kane Rob Dawson Rob Dawson 1, 10 10 silver badges 20 20 bronze badges. I Tried this in rails 4. I was trying to add "config. Spundun You're getting that error, because Rails doesn't know what store is. Thanks, I eventually figured that out. That these are nested hashes so I have to initialize empty hashes recursively if I'm to use dots in my config names.
This works in rails 3. I just wanted to update this for the latest cool stuff in Rails 4. Building on Omer Aslam's elegant solution, I decided to convert the keys into symbols. The only change is:. I like simpleconfig. It allows you to have per environment configuration. A variation to what you had in that it's a simple reference to another file.
It sees that environment. Though not a specific answer to your question of 'is it the Rails way? I prefer accessing settings through the global application stack. I avoid excess global variables in local scope. You could get settings in two ways: Settings['email'] or Settings.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Best way to create custom config options for my Rails app? Ask Question. Asked 12 years, 10 months ago. Active 3 years, 10 months ago. Viewed 74k times. However, I'm a little uneasy. A bit of paranoid caution, you can add anything you like to Rails.
The obvious use case for this sort of configuration is thing like API keys and other credentials. You can certainly use YAML files to store this information, however, just as with database.
This works in rails 3. Top 3 video Explaining How to define custom configuration variables in rails. Rails: How can I rename a database column in a Ruby on Rails migration? How to understand nil vs.
What distinguishes Heroku from AWS? How to get a random number in Ruby.
0コメント