Module: Bounga::Acts::NiceUrl::ClassMethods

Defined in:
lib/acts_as_nice_url.rb

Overview

This acts_as extension provides the capabilities for creating a nice url based on an attribute of the current object. You can set / unset the object id in front of the URL and choose the object attribute to use to generate the URL.

This extension requires Iconv to be install on your system

Author example:

class Author < ActiveRecord::Base
  acts_as_nice_url :id => false, :title => :full_name
end

Instance Method Summary collapse

Instance Method Details

#acts_as_nice_url(options = {}) ⇒ Object

Configuration options are:

  • id - specifies if the object id has to be in front of the URL or not (default: true)

  • title - specifies the object attribute to use to generate the URL. You can use a symbol

or a string (default: title)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/acts_as_nice_url.rb', line 24

def acts_as_nice_url(options = {})
  include Bounga::Acts::NiceUrl::InstanceMethods
  
  configuration = { :id => true, :title => :title }
  configuration.update(options) if options.is_a?(Hash)
  
  class_eval <<-EOV
    def nice_title
      #{configuration[:title]}
    end

    def nice_id
      #{configuration[:id]}
    end
  EOV
end