简体   繁体   中英

Rails where to put configuration like ini files?

When coding with PHP I always separate configuration values like perPage value in a separated ini file. How are you Ruby masters do this with Rails?

I would like to access config values inside my model, controller and view.

Thx!

I've generally just used a plugin like http://github.com/cjbottaro/app_config or wrote my own. I like using a config.yml file in the config directory.

Not sure about masters :) but mortal developers can usually leverage some of the existing plugins like this one: http://www.workingwithrails.com/railsplugin/5324-app-config

There are actually quite a few of them, so you'll probably find something that will suit you.

There isn't really anything built in to rails to do this, but luckily there's a great plugin called settingslogic which lets you externalise your settings.

Having said that I personally like to make these things constants in my model, so for example I'd have something like this:

class Person < AR:B
  DEFAULT_PER_PAGE = 10
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM