0

I have a model with the following associations:

class Car < ActiveRecord::Base
  belongs_to :transportation_vehicle
  belongs_to :owner
  has_many :parts

  def scrap(buyer, part)
  ...
  end
end

How would I access owner and parts in the scrap method?

1 Answer 1

1

owner or self.owner.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks Jordan. Do I need the @? I'd imagine owner would be an instance variable rather than a class variable.
to answer my own follow up, no need for @
"owner" is a method, in fact. Like many of Rails features, I believe it's generated on the fly using method_missing.
As an aside: in ruby, class variables have two @'s(@@variable), instance variables one (@variable) and things without can be either local variables or methods (which can be confusing at first, but once you get used to it it really is quite handy).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.