nettere Kalendereinttragsbearbeitung

This commit is contained in:
Andreas Stephanides
2013-11-13 11:05:04 +01:00
parent d1ae7b7da5
commit 75083064d7
7 changed files with 73 additions and 39 deletions

View File

@@ -15,8 +15,9 @@
class Calentry < ActiveRecord::Base
attr_accessible :ende, :start, :summary, :typ,:calendar_ids, :calendar, :dauer
belongs_to :calendar
belongs_to :neuigkeit
#belongs_to :neuigkeit
validates :start, :presence => true
validates :object, :presence => true
validates :typ, :presence => true
before_save :get_public
belongs_to :object, polymorphic: true # Objekt zu dem der Calentry gehört (derzeit ein Newsartikel)

View File

@@ -20,13 +20,13 @@ class Neuigkeit < ActiveRecord::Base
validates :rubrik, :presence=>true
validates :author, :presence=>true
translates :title,:text, :versioning=>true, :fallbacks_for_empty_translations => true
has_one :calentry
has_one :calentry, inverse_of: :object
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
accepts_nested_attributes_for :calentry, :allow_destroy=>true
def datum_nilsave
self.datum.nil? ? Time.now + 42.years : self.datum
end
@@ -39,6 +39,9 @@ accepts_nested_attributes_for :calentry
def reverse_publish
self.datum = nil
end
def name
self.title
end
def text_first_words
md = /<p>(?<text>[\w\s,\.!\?]*)/.match self.text
md[:text].split(" ")[0..100].join(" ")+ " ..."