On Mon, Mar 16, 2009 at 10:57 AM, Rafael George <[email protected]> wrote:
>
> Which is the best way to put global variables in my application things
> like 'items_per_page' for my pagination needs.

My smartass advice would be "don't," at least if you truly mean
"global."  Variables should stay close to the things that need them.
For your specific example, your pagination library should let you use
a configuration object or method to set that value.  (Mislav's
will_paginate definitely does.)  If you need to paginate different
numbers of items for different types of things, consider a class
attribute on those models.

For settings that are more specific to your application, if you plan
carefully enough, most of those can be attached to a relevant model,
even if you load them from a .yml file or something in an initializer
at start.  I could even see cases where controller class properties
might make sense, if that didn't lead to weird issues.

But global?  Rarely.  A global application configuration object may be
a quick shortcut some of the time, and maybe it _is_ a good place for
things that will pop up in every view and don't have any logic, like
the site name or the owner's name and e-mail, etc.  Making a
"SiteOwner" model just to keep two static fields like that is
overkill.  But for settings that modify behavior, figure out what
behavior they're touching and keep them close to that code.


-- 
Have Fun,
   Steve Eley ([email protected])
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to