public neuigkeit/rubrik -calentry link

This commit is contained in:
Andreas Stephanides
2013-08-23 13:42:19 +02:00
parent de4c84871c
commit 41433c20f9
4 changed files with 26 additions and 4 deletions

View File

@@ -15,4 +15,5 @@ class Calendar < ActiveRecord::Base
has_and_belongs_to_many :calentries
mount_uploader :picture, PictureUploader
resourcify
scope :public, -> { where(:public => :true) }
end

View File

@@ -20,8 +20,19 @@ class Neuigkeit < ActiveRecord::Base
validates :rubrik, :presence=>true
validates :author, :presence=>true
translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true
scope :published, -> {where("datum >= ?", Time.now.to_date)}
scope :recent, -> { where("updated_at >= ? ",Time.now - 7.days)}
has_one :calentry, :as => :object
scope :published, -> {where("datum >= ? AND datum IS NOT NULL", Time.now.to_date)}
scope :recent, -> { published.where("updated_at >= ? ",Time.now - 7.days)}
def datum_nilsave
self.datum.nil? ? Time.now + 42.years : self.datum
end
def public
self.rubrik.public && self.datum >=Time.now.to_date
end
def publish
self.datum = Time.now
end
def reverse_publish
self.datum = nil
end
end

View File

@@ -13,6 +13,7 @@
class Rubrik < ActiveRecord::Base
attr_accessible :desc, :name, :prio
has_many :neuigkeiten, :class_name => "Neuigkeit"
has_many :calentries, :through => :neuigkeiten, :as=>:object
resourcify
def moderator
u=User.with_role(:newsmoderator).first

View File

@@ -0,0 +1,9 @@
class AddPublicToRubrikneuigkeiten < ActiveRecord::Migration
def up
add_column :rubriken, :public,:boolean
Rubrik.update_all(:public => :true)
end
def down
remove_column :rubriken, :public
end
end