self.extended(base) class << base alias_method_chain :belongs_to, :through_option end end def belongs_to_with_through_option(association, options = {}) if options[:through] if self.reflect_on_all_associations.find { |a| a.macro == :belongs_to && a.name == options[:through] } define_method association do |*args| through_assoc = self.send(options[:through], *args) through_assoc && through_assoc.send(options[:source] || association, *args) end else raise ':through option in :belongs_to macro must be another valid :belongs_to association' end else belongs_to_without_through_option association, options end end end end
=> ["added_at > ? and deleted = ?", Time.now.utc, false], :order => "last_name, first_name") people.reject { |p| p.address.nil? } end # ... end class PeopleController < ActionController::Base def index @people = Person.find_recent end end
=> ["added_at > ? and deleted = ?", Time.now.utc, false], :order => "last_name, first_name") people.reject { |p| p.address.nil? } end # ... end class PeopleController < ActionController::Base def index @people = Person.find_recent end end
=> ["added_at > ? and deleted = ?", Time.now.utc, false], :order => "last_name, first_name") people.reject { |p| p.address.nil? } end # ... end class PeopleController < ActionController::Base def index @people = Person.find_recent end end
end def convert_to_us_dollar if currency == :us_dollar @amount elsif currency == :real @amount * ConversionRate.rate(:real, :us_dollar) end end def convert_to_real if currency == :real @amount elsif @currency == :dollar @amount * ConversionRate.rate(:us_dollar, :real) end end end
end def convert_to_us_dollar if currency == :us_dollar @amount elsif currency == :real @amount * ConversionRate.rate(:real, :us_dollar) end end def convert_to_real if currency == :real @amount elsif @currency == :dollar @amount * ConversionRate.rate(:us_dollar, :real) end end end
end def age (Date.today - @person.birthdate) / 365 end def pseudo_id @person.new_record? ? "new" : person.id end end class PeopleController < ApplicationController def show @person = PersonPresenter.new(Person.find(:id)) end end