How to find the right object in a Rails controller based on two variables?

Posted by sscirrus on Stack Overflow See other posts from Stack Overflow or by sscirrus
Published on 2010-05-15T20:31:56Z Indexed on 2010/05/15 20:34 UTC
Read the original article Hit count: 210

Hi everyone,

I have a three-table system: Companies, Customers, and Matches. The matches include, for example, private notes that each party makes about the other and some options they can set regarding the other.

I have two sets of views centered around Companies and Customers for each party to look at the other and modify their notes and settings.

# Customers Controller
def show
  @customer = Customer.find(params[:customer])
  @matchings = @candidate.matchings.find...
  @company = Company.find(params[:company])
end

Obviously the @matchings is incomplete. Given that @matchings has fields customer_id and company_id, how do I find the right matching record? Thank you!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about controller