开发者

Rails where to put configuration like ini files?

开发者 https://www.devze.com 2022-12-19 09:11 出处:网络
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?

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 a开发者_C百科nd 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消