Best practice on global settings

I have a Rails site that needs to have global access to some settings
which I would like to set in a separate file, e.g. the location of a
companion server. I have done this in a couple of ways but none of
them seems to be very elegant or Ruby-like. Does anyone have any input
on the best practice of dealing with data of this kind.

Thanks in advance

Erik L.

Erik L. wrote:

I have a Rails site that needs to have global access to some settings
which I would like to set in a separate file, e.g. the location of a
companion server. I have done this in a couple of ways but none of
them seems to be very elegant or Ruby-like. Does anyone have any input
on the best practice of dealing with data of this kind.

Thanks in advance

Erik L.

environment.rb

Thank you for the suggestion. I tried environment.rb but I think it is
not a nice solution because of the discrepancy in data types. The
settings in environment.rb is mostly directives on hov the server
should act and updates require restarting the server. What I would
like is a separate file for settings regarding the application itself,
not the server on which it is run. A trivial difference perhaps, but I
think it is an important one. I don’t like setting the preferred
graphics format for user uploads in the same place as where I set e.g.
which parts of Rails to use. I will use this solution if there are no
good alternatives but I have a feeling there are.

Regards

Erik

On 24 Okt, 12:55, Mikkel B. [email protected]

I create a module in lib folder with some text constants.

Hi

This sounds interesting. Could you give a more detailed example. Do
you use module variables or module instance variables, where do you
include it and so on. Do you know of any articles on this subject. I
would be very thankful for the assistance.

Kindest regards

Erik

On 24 Okt, 13:59, “[email protected]

Hi

This sounds interesting. Could you give a more detailed example. Do
you use module variables or module instance variables, where do you
include it and so on. Do you know of any articles on this subject. I
would be very thankful for the assistance.

Kindest regards

Erik

On 24 Okt, 13:59, “[email protected]

On Oct 24, 5:14 am, Erik L. [email protected] wrote:

On 24 Okt, 13:59, “[email protected]

[email protected] wrote:

I create a module in lib folder with some text constants.

some time ago, somebody suggested searching ageilwebdev.com on
“settings”, it works:

http://agilewebdevelopment.com/plugins/search?search=settings

Many thanks, I will try that.

/Erik

On 24 Okt, 15:14, “[email protected]

lib\somefile.rb

module MySettingsContainer
SOMETEXT = “SOME TEXT VALUE”
end

controller

requere “somefile.rb” (or require lib/somefile.rb)

class AAA < AplicationController
include MySettingsContainer # i think it’s not needed

def index
@result = MySettingsContainer::SOMETEXT
end

end

On Wed, 24 Oct 2007 04:03:54 -0700, Erik L. wrote:

Thank you for the suggestion. I tried environment.rb but I think it is
not a nice solution because of the discrepancy in data types. The
settings in environment.rb is mostly directives on hov the server
should act and updates require restarting the server. What I would
like is a separate file for settings regarding the application itself,
not the server on which it is run.

How about:

  • Use the app_config plugin to get a nice syntax
  • Add a line in config/environment.rb to ‘require application’
  • Put the app_config stuff in config/application.rb

I think that’ll work, unless ‘require application’ ends up loading one
of
the other application.rb files due to load path order, in which case you
should be able to do something like require “#{config_dir}/application”.


Jay L. |
Boston, MA | My character doesn’t like it when they
Faster: jay at jay dot fm | cry or shout or hit.
http://www.jay.fm | - Kristoffer