views:

60

answers:

1

How to place a drop down for the virtual column, in the ruby on rails. The virutal column does not exist in my table , but I want to get the value from the drop down ,when user saves the data.

for example,

product_price is a virtual column , which doesn't exist in my database table. But I would like to have a dropdown, with product price to be displayed from another table. And when user selects the product_price, the selected product_price should be gettable in an object as self.product_price.

Virtual column for labels is working fine, but for drop down its not working for me..any info woud be Thankful...

A: 
class Product
  belongs_to :product_price
end
class ProductPrice
  #assume a field called "price"
  has_many :products
end

<% form_for @product do |f| -%>
    <%= f.select("product_price_id", ProdcuctPrice.all.collect {|p| [ p.price, p.id ] })
<% end -%>
MattMcKnight