好的,这就是我所拥有的
wines 表中的列-> ID,价格表中的名称
列-> ID,wine_id,价格
@query = Wine.find(:all)
现在如何向@query 哈希添加自定义价格列?这可以做到吗?
这就是我最终想要的
<% @query.each do |e| %>
<%= e.price %>
<% end %>
编辑:
实际表结构
葡萄酒有很多库存
库存有一个葡萄酒
库存有一个区域
库存有很多可用性可用性有一个库存
可用性有一个 Markupprofile_id
可用性有一个 Discountprofile_id
这是我遵循的过程
#special offers
@q_array = Array.new
@q = SpecialOffers.find(:all, :conditions => ["client_id = ? AND application_id = ?", @client_id, @app_id])
@q.each do |e|
@q_array << e.availability_id
end
#filter, Special Offers, Client App Id, Zone, Available
@special_offers = Wine.find(:all, :include => [:availabilities, :zones], :conditions => ["availabilities.available = ? AND availabilities.id IN (?) AND availabilities.client_application_id = ? AND zones.id = ?", true, @q_array, @client_app_id, session[:zone_id]], :order => 'wines.name ASC')
#search page = 1, new arrivals = 2, special offers = 3, best sellers = 4, show page = 5
add_markup(@special_offers, 3)
现在我有了我想要的葡萄酒,我通过add_markup()运行它们
def add_markup(collection, unique)
@price_array ||= [] #if null create blank array
collection.each do |e|
e.inventories.each do |f|
if session[:zone_id] == f.zone_id
@availability = Availability.find_by_inventory_id_and_client_application_id(f.id, @client_app_id)
@price = f.price
if @availability
if @availability.discount == true
price = Pricingmodel.find_by_discountprofile_id(@availability.discountprofile_id)
if price
was_price = Pricingmodel.find_by_markupprofile_id(@availability.markupprofile_id)
f.price = ((price.markup.to_f / 100) + 1) * @price * 6 #this is the normal price
f.stock = ((was_price.markup.to_f / 100) + 1) * @price * 6 #this is the discounted price
else
price = Pricingmodel.find_by_markupprofile_id(@availability.markupprofile_id)
f.price = ((price.markup.to_f / 100) + 1) * @price * 6 #this is the normal price
f.stock = ((price.markup.to_f / 100) + 1) * @price * 6 #this is the discounted price
end
else
price = Pricingmodel.find_by_markupprofile_id(@availability.markupprofile_id)
f.price = ((price.markup.to_f / 100) + 1) * @price * 6 #this is the normal price
f.stock = ((price.markup.to_f / 100) + 1) * @price * 6 #this is the discounted price
end
end
end
end
end
end
f.price 还可以,正常价格。问题是,我还想在
某个位置显示折扣
价)有什么办法可以“添加”一个 of_type 浮点列到这个集合中?可以说float类型的discounted_price列?这可以做到吗?