Ok, here is what I have
columns in wines table -> ID, Name
columns in price table -> ID, wine_id, price
@query = Wine.find(:all)
now how do I add a custom price column to the @query hash? Can this be done?
This is what I want in the end
<% @query.each do |e| %>
<%= e.price %>
<% end %>
EDIT:
Actual table structure
Wines has many Inventories
Inventories has one Wine
Inventories has one Zone
Inventories has many AvailabilitiesAvailabilities has one Inventory
Availabilities has one Markupprofile_id
Availabilities has one Discountprofile_id
This is the process I follow
#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)
Now I have the wines I want and I run them through 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 is fine, its the normal price.
The problem is, I want to also display the discounted price somewhere
I used the stock column wich is of type int for this discounted price (f.stock = ((was_price.markup.to_f / 100) + 1) * @price * 6)
Is there any way I could "add" a of_type float column to this collection? Lets say discounted_price column of type float? Can this be done?