This is a many(proposaltracking)-to-one(partner) relationship.
I am getting undefined method 'reference' for ProposalTracking:Class error with @company.proposalTracking.reference
When I run @company.proposalTracking it returns me the ProposalTracking object.
Here is my model:
class ProposalTracking < ActiveRecord::Base
set_table_name "Proposal_Tracking"
belongs_to :partner
end
class Partner < ActiveRecord::Base
has_many :proposalTracking
end
What I want to get is the attributes of proposalTracking like
@company = Partner.find(params[:id])
@company.proposalTracking.reference
but this results in the error undefined method 'reference' for ProposalTracking:Class
I have read solutions where it is because since it is a one-to-many relation, the partner may have more than one track proposal so I would have to grab the first one using .first but I tried this and it then says
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.reference
Any help would be much appreciated!
It should be
and you can access it via
@company.proposal_trackings. But that’s actually an array of ProposalTracking instances (because of has_many) that you have to iterate over to get each attribute@company.proposal_trackings.map(&:reference)