# Using another objects methods within another object

**URL:** <https://www.ruby-forum.com/t/using-another-objects-methods-within-another-object/141457>\
**Category:** Rails\
**Created:** [June 26, 2008, 12:45am UTC](https://www.ruby-forum.com/t/using-another-objects-methods-within-another-object/141457 "2008-06-26T00:45:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GearSSS\_id\_OSCealla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@GearSSS\_id\_OSCealla](https://www.ruby-forum.com/u/GearSSS_id_OSCealla)\
**Post date:** [June 26, 2008, 12:45am UTC](https://www.ruby-forum.com/t/using-another-objects-methods-within-another-object/141457/1 "2008-06-26T00:45:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GearSSS\_id\_OSCealla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@GearSSS\_id\_OSCealla](https://www.ruby-forum.com/u/GearSSS_id_OSCealla)\
**Post date:** [June 26, 2008, 9:41am UTC](https://www.ruby-forum.com/t/using-another-objects-methods-within-another-object/141457/2 "2008-06-26T09:41:14Z")

</div>

On Jun 25, 11:44 pm, Gearóid O’Ceallaigh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![GearSSS\_id\_OSCealla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b9bd4f/32.png) [@GearSSS\_id\_OSCealla](https://www.ruby-forum.com/u/GearSSS_id_OSCealla)\
**Post date:** [June 26, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/using-another-objects-methods-within-another-object/141457/3 "2008-06-26T16:18:52Z")

</div>

On 25 jun, 19:44, Gearóid O’Ceallaigh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
