Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
show all
- Defined in:
- lib/active_record_extensions/active_record_extensions.rb
Class Method Summary
collapse
Class Method Details
.object_id_attr(symbol, klass) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/active_record_extensions/active_record_extensions.rb', line 13
def self.object_id_attr(symbol, klass)
module_eval %{
def #{symbol}
if @#{symbol}.nil? or (@old_#{symbol}_id != #{symbol}_id)
@old_#{symbol}_id = #{symbol}_id
klass = #{klass}.descendants.find { |d| d.#{symbol}_name == #{symbol}_id }
klass ||= #{klass}
@#{symbol} = klass.new
else
@#{symbol}
end
end
}
end
|
.validates_path(*args) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/active_record_extensions/active_record_extensions.rb', line 5
def self.validates_path(*args)
configuration = args.
validates_each(args, configuration) do |record, attr_name, value|
page = Page.find_by_path(value)
record.errors.add(attr_name, :page_not_found, :default => configuration[:message]) if page.nil? || page.is_a?(FileNotFoundPage)
end
end
|