Skip to content

Instantly share code, notes, and snippets.

@htmiguel
Created July 11, 2013 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htmiguel/09ccca6b08334520c6be to your computer and use it in GitHub Desktop.
Save htmiguel/09ccca6b08334520c6be to your computer and use it in GitHub Desktop.
class Deal < ActiveRecord::Base
attr_accessible :dealer_location, :model_year, :manufacturer,
:model, :vehicle_trim, :vehicle_type, :expires_on,
:monthly_fee, :due_at_signing, :release_year,
:term_length, :total_miles_per_year, :total_miles,
:image, :image_remote_url
has_attached_file :image,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "/images/:style/missing.png"
extend FriendlyId
friendly_id :slug_candidates, use: :slugged
scope :available, where('expires_on >= ?', Time.now).order('expires_on ASC')
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
Deal.delay.create! row.to_hash
end
end
def image_remote_url=(url_value)
self.image = URI.parse(url_value)
@image_remote_url = url_value
end
def slug_candidates
[[self.model_year, self.manufacturer, self.model, self.vehicle_trim]]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment