Module: Withardry

Defined in:
lib/withardry/base.rb,
lib/withardry/version.rb

Constant Summary collapse

VERSION =
"0.2.2"

Instance Method Summary collapse

Instance Method Details

#friendly_url(field = :name) ⇒ Object

example: friendly_url OR friendly_url :title



13
14
15
16
17
18
19
20
# File 'lib/withardry/base.rb', line 13

def friendly_url(field = :name)
  define_method(:to_param) do
    attribute = self.send(field)
    stack = [id.to_s]
    stack << attribute.parameterize if attribute.present?
    stack.join("-")
  end
end

#withardry(name, options = {}) ⇒ Object

example: withardry OR withardry :user, :prefix => “by”, :as => “user_id”



4
5
6
7
8
9
# File 'lib/withardry/base.rb', line 4

def withardry(name, options = {})
  field  = options[:as]     || name
  prefix = options[:prefix] || "with"
  
  scope "#{prefix}_#{name}", lambda {|value| where("#{field}" => value) }
end