Gearóid O'Ceallaigh
2008-Jun-25 22:44 UTC
Using another objects methods within another object
Hey, I''m just getting used to ruby on rails and im designing a website that has a forum and a list of events. So there are two models: forum and event. I''ve got a method for event called find_upcoming_events which is used to list all future events. But I''d like to show the upcoming events at the bottom of the forum page but I''m unable to do this since the function belongs to event and not forum. Can anyone tell me how I could do this? Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-26 07:40 UTC
Re: Using another objects methods within another object
On Jun 25, 11:44 pm, Gearóid O''Ceallaigh <gearoi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey, > > I''m just getting used to ruby on rails and im designing a website that > has a forum and a list of events. So there are two models: forum and > event. > > I''ve got a method for event called find_upcoming_events which is used > to list all future events. But I''d like to show the upcoming events at > the bottom of the forum page but I''m unable to do this since the > function belongs to event and not forum.Sounds like find_upcoming_events should be a class method on Event, which would mean you could call Event.find_upcoming_events (which I''d probably shorten to Event.find_upcoming) anywhere you want. If that sentence was gibberish, I suggest you read a little more about ruby/ object oriented programming in general. Fred> > Can anyone tell me how I could do this? Thanks in advance.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
krusty.ar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jun-26 14:18 UTC
Re: Using another objects methods within another object
On 25 jun, 19:44, Gearóid O''Ceallaigh <gearoi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey, > I''ve got a method for event called find_upcoming_events which is used > to list all future events. But I''d like to show the upcoming events at > the bottom of the forum page but I''m unable to do this since the > function belongs to event and not forum. >In the forum controller index action, set @upcoming_events = Event.upcoming The Event::upcoming method could be a proxy to find with some filters, or just a named_scope (look for it). Lucas. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---