calentries -neuigkeiten calender fix

This commit is contained in:
Andreas Stephanides
2013-10-04 16:11:36 +02:00
parent 0fe92a4b48
commit 2e01fd574b
13 changed files with 63 additions and 28 deletions

View File

@@ -11,10 +11,13 @@
#
class Calendar < ActiveRecord::Base
attr_accessible :name, :public, :picture
has_and_belongs_to_many :calentries
attr_accessible :name, :public, :picture, :rubrik_id
has_many :calentries
mount_uploader :picture, PictureUploader
belongs_to :rubrik
validates :rubrik, :presence=>true
resourcify
scope :public, -> { where(:public => :true) }
scope :public_cals, -> { where(:public => :true) }
end

View File

@@ -13,8 +13,9 @@
#
class Calentry < ActiveRecord::Base
attr_accessible :ende, :start, :summary, :typ,:calendar_ids
has_and_belongs_to_many :calendars
attr_accessible :ende, :start, :summary, :typ,:calendar_ids, :calendar
belongs_to :calendar
belongs_to :neuigkeit
validates :start, :presence => true
validates :typ, :presence => true
before_save :get_public
@@ -28,7 +29,7 @@ validate do |entry|
resourcify
def get_public
self.public = (self.try(:object).nil?)? (self.calendars.public.count>0) : object.try(:public)
self.public = (self.try(:object).nil?)? (self.calendar.try(:public)) : object.try(:public)
true
end
def start_time

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
has_many :memberships, dependent: :delete_all
has_many :gremien, :through=> :membership
mount_uploader :picture, PictureUploader

View File

@@ -14,18 +14,19 @@
class Neuigkeit < ActiveRecord::Base
attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture
attr_accessible :datum, :text, :title, :rubrik_id, :author_id,:picture, :calentry_attributes
belongs_to :author, :class_name =>'User'
belongs_to :rubrik, :class_name =>'Rubrik', :foreign_key => "rubrik_id"
validates :rubrik, :presence=>true
validates :author, :presence=>true
translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true
has_one :calentry, :as => :object
has_one :calentry
mount_uploader :picture, PictureUploader
scope :published, -> {where("datum <= ? AND datum IS NOT NULL", Time.now.to_date).order(:datum).reverse_order}
scope :recent, -> { published.where("updated_at >= ? ",Time.now - 7.days)}
scope :unpublished, -> {where("datum >= ? OR datum IS NULL", Date.today)}
scope :public, ->{includes(:rubrik).where("rubriken.public"=>:true)}
accepts_nested_attributes_for :calentry
def datum_nilsave
self.datum.nil? ? Time.now + 42.years : self.datum
end

View File

@@ -11,7 +11,7 @@
#
class Rubrik < ActiveRecord::Base
attr_accessible :desc, :name, :prio
attr_accessible :desc, :name, :prio, :calendar
has_many :neuigkeiten, :class_name => "Neuigkeit"
has_many :calentries, :through => :neuigkeiten, :as=>:object
resourcify