开发者

Appropriate place to store globals (not constants!) in Rails 3

I browsed the related questions but I couldn't find what I needed since most questions were asking where to store constants, not simply globals.

I'd like my CMS to randomly select a color scheme at the click of a button. Before a user auto-generates the colorscheme though, I'd like to be able to load a default one from a number of variables. What's a good place for those sorts of things?

Up until now I've been storing settings in a database, but I wonder if there's a simple way. For some开发者_JAVA技巧 reason placing them in the environment.rb nor initializers.rb doesn't seem to do the trick.

I'd like to note that I wnat these variables to be editable; constants are no good.


Do you want the user to only change the color scheme for their account? If so, that setting should be stored in the database associated with that user.

If you store the value in a Ruby constant like $color in config/initializers/color.rb, it will be set and re-set for all users hitting that running instance of the Rails app. Say you have three production Rails processes running in a web server like Thin, 33% (depending on your load balancer) of the users will see the same color.

$color in an initializer should work locally but you'll have to restart your server after creating the variable.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜