# Payment.find\_by\_person\_and\_event

**URL:** <https://www.ruby-forum.com/t/payment-find-by-person-and-event/137304>\
**Category:** Rails\
**Created:** [May 11, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/payment-find-by-person-and-event/137304 "2008-05-11T19:11:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kopf1988](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/74df32/32.png) [@kopf1988](https://www.ruby-forum.com/u/kopf1988)\
**Post date:** [May 11, 2008, 7:11pm UTC](https://www.ruby-forum.com/t/payment-find-by-person-and-event/137304/1 "2008-05-11T19:11:19Z")

</div>

Hey, I need help with a little something that I thought SHOULD work.

I’m getting this error:  
ActionView::TemplateError (undefined method `find\_by\_person\_and\_event’  
for Payment:Class) on line #2 of app/views/people/\_attending.rhtml:  
1: \<% for event in @person.events %\>  
2: \<% payment = Payment.find\_by\_person\_and\_event(@person,event) %\>  
3: Attending \<%= event.name %\>, as a \<%= payment.price.name %\>.  
4:  
5:

But here’s my Payment class, it looks correct:  
class Payment \< ActiveRecord::Base  
has\_many :attendances  
has\_many :person, :through =\> :attendance  
has\_many :event, :through =\> :attendance  
belongs\_to :price  
end

Any ideas why those find\_by methods simply are not working? Rails  
never likes me when it comes to using them… I still haven’t figured  
out the enigma.

---

<div class="post-metadata">

**Author:** ![kopf1988](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/74df32/32.png) [@kopf1988](https://www.ruby-forum.com/u/kopf1988)\
**Post date:** [May 11, 2008, 7:57pm UTC](https://www.ruby-forum.com/t/payment-find-by-person-and-event/137304/2 "2008-05-11T19:57:13Z")

</div>

On 11 May 2008, at 18:10, kopf1988 wrote:

> 5:
> 
> But here’s my Payment class, it looks correct:  
> class Payment \< ActiveRecord::Base  
> has\_many :attendances  
> has\_many :person, :through =\> :attendance  
> has\_many :event, :through =\> :attendance  
> belongs\_to :price  
> end

They work on database attributes (not association names or anything  
like that) so the method you’re after is  
find\_by\_person\_id\_and\_event\_id (and you’ll probably need to pass in  
@person.id instead of @person etc…)

Fred
