Class: NewsArticle

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/news_article.rb

Instance Method Summary collapse

Instance Method Details

#category_nameObject



30
31
32
# File 'app/models/news_article.rb', line 30

def category_name
  category ? category.name : nil
end

#monthObject



49
50
51
# File 'app/models/news_article.rb', line 49

def month
  release_date ? release_date.month : nil
end

#route_paramsObject



38
39
40
41
42
43
# File 'app/models/news_article.rb', line 38

def route_params
  {:year => release_date.strftime("%Y"), 
    :month => release_date.strftime("%m"), 
    :day => release_date.strftime("%d"), 
    :slug => slug}
end

#set_attachment_file_pathObject



59
60
61
62
63
# File 'app/models/news_article.rb', line 59

def set_attachment_file_path
  if new_record? && !attachment_file.blank?
    attachment.file_path = "/news/articles/attachment/#{Time.now.to_s(:year_month_day)}/#{name.to_slug}.#{attachment_file.original_filename.split('.').last.to_s.downcase}" 
  end
end

#set_attachment_sectionObject



53
54
55
56
57
# File 'app/models/news_article.rb', line 53

def set_attachment_section
  if new_record? && !attachment_file.blank?
    attachment.section = Section.first(:conditions => {:name => 'News'})
  end
end

#set_slugObject



34
35
36
# File 'app/models/news_article.rb', line 34

def set_slug
  self.slug = name.to_slug unless name.blank?
end

#yearObject



45
46
47
# File 'app/models/news_article.rb', line 45

def year
  release_date ? release_date.year : nil
end