I have always like constants for "global" variables. It comes from
programming C I think. Having model related constants in your
controllers is really not the MVC way IMHO. A constant is easy to
setup in ActiveRecord and in my opinion are much more readable. And
guess what, I actually did it with an Article model too! =>
class Article < ActiveRecord::Base
...
ARTS_CATEGORY = Category.find(:first, :conditions => ['name LIKE ?',
'arts%']).id
OPINE_CATEGORY = Category.find(:first, :conditions => ['name
LIKE ?', 'opine%']).id
DISTRACTIONS_CATEGORY = Category.find(:first, :conditions => ['name
LIKE ?', 'distra%']).id
NEWS_POLITICS_CATEGORY = Category.find(:first, :conditions => ['name
LIKE ?', 'news%']).id
...
So in my controllers I use a method like this (the actual method is a
shared method for all "types" longer, this is for readability:
...
def arts_archive
Article.find_by_category_id(Article::ARTS_CATEGORY)
end
...
On Nov 15, 2:47 pm, Mario Peterscheck <[EMAIL PROTECTED]
s.net> wrote:
> ... thanks Pau,
>
> indeed you're right, and by the way, the same way has been suggested in
> a different board.
>
> Thanks alot, greetings
> Mayo
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---