简体   繁体   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. 表中不存在virutal列,但是当用户保存数据时,我想从下拉列表中获取值。

for example, 例如,

product_price is a virtual column , which doesn't exist in my database table. product_price是一个虚拟列,在我的数据库表中不存在。 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. 当用户选择product_price时,所选的product_price应该可以在对象中作为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 -%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM