开发者

Where to store config for a rails plugin

I'm working on a plugin for rails to provide some simple diagnostic information about external 开发者_StackOverflow中文版systems for purposes of monitoring etc. primarily as an exercise to learn more about rails.

I need to know where config variables for this type of rails plugin belongs, in this case I need to store an array of ip addresses and ports that point at these external services so that I can access it in my plugins controllers e.g.

['127.0.0.1:12345', '192.168.1.1:54321']

I'm currently using Rails 3.1.


You could create a new file in config/initializers, e.g. globals.rb:

EXTERNAL_SERVICE_IP_1 = "some ip"


There are many answers to this question depending on what you really expect:

  • define a constant in a class or a module (with or without yml)

  • define two methods in a class or a module: one to get a variable (with default value) and another to set and change the value

How do you want to use it?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜