On Dec 15, 2010, at 12:04 PM, Colin Law wrote:

On 15 December 2010 17:01, Tim Shaffer <[email protected]> wrote:
You could just use a method instead...

class User < ActiveRecord::Base

  has_many :payments

  def testing_payments
    payments.where(:testing => testing)
  end

That would be even better as a named scope.

Colin


Actually, it would be better if it worked:

class User < ActiveRecord::Base
  has_many :payments

  def testing_payments
    payments.where(:testing => true)  # testing is a local?
  end
end


somebody = User.find(params[:id])

Then, you could say:
        somebody.testing_payments

Or add a scope to Payment

class Payment < ActiveRecord::Base
  belongs_to :user

  scope :testing, where(:testing => true)
end

And you'd say:
        somebody.payments.testing

Either would work. If testing is a instance method of User, then the original suggestion might actually be "better."

-Rob

Rob Biedenharn          
[email protected]     http://AgileConsultingLLC.com/
[email protected]               http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to