Module: Railslove::Plugins::FindByParam

Defined in:
lib/find_by_param.rb,
lib/find_by_param/version.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods, SingletonMethods

Constant Summary collapse

VERSION =
'0.2.1'

Class Method Summary collapse

Class Method Details

.enableObject

:nodoc:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/find_by_param.rb', line 12

def self.enable # :nodoc:
  return if ActiveRecord::Base.kind_of?(self::ClassMethods)

  ActiveRecord::Base.class_eval do
    if respond_to? :class_attribute
      class_attribute :permalink_options
    else
      class_inheritable_accessor :permalink_options
    end

    self.permalink_options = {:param => :id}

    #default finders these are overwritten if you use make_permalink in
    # your model
    def self.find_by_param(value,args={}) # :nodoc:
      find_by_id(value,args)
    end
    def self.find_by_param!(value,args={}) # :nodoc:
      find(value,args)
    end
  end
  ActiveRecord::Base.extend(self::ClassMethods)
end