English 中文(简体)
virtual column for drop down in the ruby on rails
原标题:

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...

问题回答
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 -%>




相关问题
virtual column for drop down in the ruby on rails

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 ...

C++ : implications of making a method virtual

Should be a newbie question... I have existing code in an existing class, A, that I want to extend in order to override an existing method, A::f(). So now I want to create class B to override f(), ...

C++ static virtual members?

Is it possible in C++ to have a member function that is both static and virtual? Apparently, there isn t a straightforward way to do it (static virtual member(); is a compile error), but is there at ...

C++ collection of abstract base classes

how can I create STL collection of classes which implement abstract base class using the base class as collection value, without using pointers? is there something in Boost that allows me to ...

How to design a C++ API for binary compatible extensibility

I am designing an API for a C++ library which will be distributed in a dll / shared object. The library contains polymorhic classes with virtual functions. I am concerned that if I expose these ...

热门标签