This doesn't seem like the best way to use a global variable. If you are 
doing something like displaying those 3 articles on lots of pages, then 
maybe you want something like this in application.rb:
before_filter :get_recent_articles

def get_recent_articles
  @articles = Article.recent
end


Then you will be able to access @articles in every view (with <% 
articles.each do |article| %> etc). And you will have access to 
@articles in all your controller actions.

You won't have access to @articles in your models though. But there you 
could just call Article.recent.

Note: the above code uses a named scope like this (in article.rb)
named_scope :recent, :limit => 3, :order => 'created_at DESC'

What I'm suggesting doesn't sound perfect to me (I'm just writing this 
quickly). But I think it is a better way to organize it than I global 
variable.
-- 
Posted via http://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
-~----------~----~----~----~------~----~------~--~---

Reply via email to