55 lines
1.6 KiB
Ruby
55 lines
1.6 KiB
Ruby
class Particular < ActiveRecord::Base
|
|
has_many :p_contacts, :as => :contactable
|
|
accepts_nested_attributes_for :p_contacts
|
|
|
|
|
|
belongs_to :owner, :polymorphic => true
|
|
validates :name, :presence => true, :if => :force_validation?
|
|
validates :firstname, :presence => true, :if => :force_validation?
|
|
validates :email, :presence => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :if => :force_email_validation
|
|
validates :address_2, :presence => true, :if => :force_validation?
|
|
validates :cp, :presence => true, :if => :force_validation?
|
|
validates :city, :presence => true, :if => :force_validation?
|
|
validates :country, :presence => true, :if => :force_validation?
|
|
#validates :tel, :presence => true, :if => :force_validation?
|
|
validates :organisation, :presence => true, :if => :validate_pro
|
|
attr_accessor :force_validation
|
|
def validate_pro
|
|
true if self.force_validation and self.pro
|
|
end
|
|
def force_email_validation
|
|
false
|
|
#true if (self.validate_email or self.force_validation) and !skip_email
|
|
end
|
|
def force_validation?
|
|
puts "TESTTTT"
|
|
puts self.force_validation
|
|
if self.force_validation
|
|
true
|
|
else
|
|
false
|
|
end
|
|
end
|
|
|
|
def address_longue
|
|
address_2.to_s + " " + address_3.to_s
|
|
end
|
|
|
|
|
|
|
|
def address_line
|
|
r = ""
|
|
r+= self.organisation+" " if self.organisation?
|
|
r+= self.name+" " if self.name?
|
|
r+= self.firstname+" " if self.name?
|
|
r+= self.address_1+" " if self.address_1?
|
|
r+= self.address_2+" " if self.address_2?
|
|
r+= self.address_3+" " if self.address_3?
|
|
r+= self.cp+" " if self.cp?
|
|
r+= self.city+" " if self.city?
|
|
return r
|
|
|
|
end
|
|
|
|
end
|