# Grabbing associated value from database

**URL:** <https://www.ruby-forum.com/t/grabbing-associated-value-from-database/107338>\
**Category:** Rails\
**Created:** [June 20, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/grabbing-associated-value-from-database/107338 "2007-06-20T18:07:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [June 20, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/grabbing-associated-value-from-database/107338/1 "2007-06-20T18:07:03Z")

</div>

i’m posting a promo code from a form and need to grab the relavant  
information from the database to apply it properly to the amount be  
paid so that the discount is applied.

the value posted is params[:promo\_code][:code]

how can i grab this from the database

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [June 20, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/grabbing-associated-value-from-database/107338/2 "2007-06-20T20:27:27Z")

</div>

Anyone know the easy way to do this?

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [June 20, 2007, 9:32pm UTC](https://www.ruby-forum.com/t/grabbing-associated-value-from-database/107338/3 "2007-06-20T21:32:37Z")

</div>

On 6/20/07, jonathan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i’m posting a promo code from a form and need to grab the relavant  
> information from the database to apply it properly to the amount be  
> paid so that the discount is applied.
> 
> the value posted is params[:promo\_code][:code]
> 
> how can i grab this from the database

Assuming you have a table called promo\_codes (and an associated  
PromoCode model), you could fetch the data with:

@row = PromoCode.find\_by\_code(params[:promo\_code][:code])

Is that what you’re asking?
