fetprofileprivate data

This commit is contained in:
2014-05-27 19:41:35 +05:30
parent 015bf132a9
commit 13514317c9
10 changed files with 116 additions and 11 deletions

View File

@@ -15,7 +15,7 @@
#
class Fetprofile < ActiveRecord::Base
attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname, :memberships_attributes, :remove_picture, :picture_cache
attr_accessible :active, :desc, :fetmailalias, :nachname, :picture, :short, :vorname, :memberships_attributes, :remove_picture, :picture_cache, :plz, :street, :city, :instant,:skype, :telnr, :hdynr, :birth_day,:birth_month, :birth_year
has_many :memberships, dependent: :delete_all
has_many :gremien, :through=> :membership
mount_uploader :picture, PictureUploader
@@ -23,11 +23,18 @@ class Fetprofile < ActiveRecord::Base
validates :desc, :presence=>true
validates :nachname, length:{minimum: 3},:presence=>true
validates :vorname, length:{minimum: 3},:presence=>true
validate :validate_birthday
has_many :users
scope :search, ->(query) {where("nachname like ? or vorname like ? or short like ?", "%#{query}%", "%#{query}%", "%#{query}%")}
accepts_nested_attributes_for :memberships, :reject_if=>lambda{|a| a[:typ].blank?|| a[:start].blank? ||a[:gremium_id].blank?}, :allow_destroy=>true
has_many :nlinks, as: :link
def validate_birthday
unless Date.valid_date?(birth_year, birth_month, birth_day)
errors.add(:birth_month, "Invalides Datum")
errors.add(:birth_day, "Invalides Datum")
end
end
def title
self.name
@@ -39,4 +46,15 @@ validates :desc, :presence=>true
def fetmail
(fetmailalias.nil? || fetmailalias.empty?) ? short.to_s + "@fet.at" : fetmailalias.to_s + "@fet.at"
end
def adress
connector= (self.street.nil?||self.street.empty?||(self.city.empty? && self.plz.empty?)) ? '' : ', '
self.plz.to_s + ' ' + self.city.to_s + connector.to_s + self.street.to_s
end
def birthday
if self.birth_year.nil? || self.birth_year.zero?
Date.new( Date.today.year,self.birth_month,self.birth_day)
else
Date.new( self.birth_year,self.birth_month,self.birth_day)
end
end
end