Class: Humpyard::NewsItem

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

Instance Method Summary collapse

Instance Method Details

#human_url(options = {}) ⇒ Object

Return the human readable URL for the page.

Posible options values are

:locale

A locale given in the Humpyard::Config.locales. If no :locale is given the option will be ::I18n.locale by default



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/humpyard/news_item.rb', line 21

def human_url(options={})
  options[:locale] ||= ::I18n.locale
  options[:format] ||= :html
  
  unless Humpyard::config.locales.include? options[:locale].to_sym
    options[:locale] = Humpyard::config.locales.first
  end
  
  if options[:path_format]
    format = "/"
  else
    format = ".#{options[:format].to_s}" 
  end
  
  page_options = options
  page_options[:path_format] = true
  
  "#{news_page.page.human_url(page_options)}#{created_at.strftime '%Y/%m/%d'}/#{query_title_for_url(options[:locale])}#{format}"
end