Sha256: 1fcf1e5a30d86f23fe45197eecef7fe5bc696a2d00195a68db490be4ad7dff6a

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module Humpyard
  class NewsItem < ::ActiveRecord::Base
    set_table_name "#{Humpyard::config.table_name_prefix}news_items"

    belongs_to :news_page, :class_name => "Humpyard::Pages::NewsPage", :foreign_key => "news_page_id"

    require 'globalize'

    translates :title, :title_for_url, :content
    has_title_for_url
        
    validates_presence_of :title
    
    
    # Return the human readable URL for the page.
    #
    # Posible options values are
    # <tt>:locale</tt>:: 
    #     A locale given in the Humpyard::Config.locales.
    #     If no <tt>:locale</tt> is given the option will be ::I18n.locale by default
    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
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
humpyard-0.0.1 app/models/humpyard/news_item.rb