# How to show price on store list?

**URL:** <https://www.ruby-forum.com/t/how-to-show-price-on-store-list/172733>\
**Category:** Rails\
**Created:** [July 27, 2009, 7:24am UTC](https://www.ruby-forum.com/t/how-to-show-price-on-store-list/172733 "2009-07-27T07:24:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike75](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@Mike75](https://www.ruby-forum.com/u/Mike75)\
**Post date:** [July 27, 2009, 7:24am UTC](https://www.ruby-forum.com/t/how-to-show-price-on-store-list/172733/1 "2009-07-27T07:24:37Z")

</div>

hi…  
I have separated a product table and a price table,  
because One product can have many prices.  
Users choose a bag\_size from the drop down box.

ex) a prodct “a” has 2 bag size(1,2)  
a price of 1 is $4.99  
a price of 2 is $5.99

ex) a product “b” has 3 bag size(1, 2, 3)  
a price of 1 is $3.99  
a price of 2 is $4.99  
a price of 3 is $5.99

now I’d like to show a list of products with prices of each.

# index(store)

\<%= collection\_select “bagList”, :price,  
@prices, :price, :bag\_size, :prompt =\>“Bag Size” %\>

# controller(store)

@prices = Price.find(:all)

# model(price)

belongs\_to :product, :foreign\_key =\> :product\_id

# model(product)

has\_many :prices, :dependent =\> :destroy

the above code shows all the prices on the price list…

||product “a” || product “b”||  
||price 1,2,1,2,3||price 1,2,1,2,3||

well, i’d like to show products and a drop down select list with their  
own prices…  
||product “a” || product “b”||  
||price 1,2||price 1,2,3||

anyone can help me out, pls?

---

<div class="post-metadata">

**Author:** ![Mike75](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac8455/32.png) [@Mike75](https://www.ruby-forum.com/u/Mike75)\
**Post date:** [July 27, 2009, 8:09am UTC](https://www.ruby-forum.com/t/how-to-show-price-on-store-list/172733/2 "2009-07-27T08:09:42Z")

</div>

i got it working by

\<%= collection\_select “bagList”, :price, Price.find  
(:all, :conditions=\>[“product\_id=?”,  
product.id]), :price, :bag\_size, :prompt =\>“Bag Size” %\>

thanx…
