Sha256: 376c4031c457da637b0d01a6919814aabeba620a43316f9f540c02670f700e8f

Contents?: true

Size: 595 Bytes

Versions: 4

Compression:

Stored size: 595 Bytes

Contents

class Product < ActiveRecord::Base
  include ActionView::Helpers::NumberHelper

  validates_presence_of :name, :permalink, :shipping_weight

  has_many :photos
  
  def photos?
    self.photos.present?
  end

  def price? ; self.price_exists?(self.price)  ; end
  def pricef ; self.format_price(self.price)   ; end

  def sale?       ; self.price_exists?(self.sale_price)  ; end
  def sale_pricef ; self.format_price(self.sale_price)   ; end

  protected

  def format_price(price)
    number_to_currency(sprintf("%.02f", price))
  end

  def price_exists?(price)
    price.to_f > 0
  end


end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ecommerce-0.0.6 app/models/product.rb
ecommerce-0.0.5 app/models/product.rb
ecommerce-0.0.4 app/models/product.rb
ecommerce-0.0.3 app/models/product.rb