I am trying to make an app in Rails 4.
My profiles form allows users to make a profile. A section of the profile is for their qualifications.
The associations are:
profile.rb
has_many :qualifications
accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true
qualifications rb
belongs_to :profile
My profiles view folder then includes a partial to show that profile's qualifications. The show partial has:
<% Qualification.pending.order(year_earned: :asc).each do |qualification| %>
<div class="row">
<div class="col-md-12">
<div class="profilequalifications">
<%= qualification.current_study %>
</div>
</div>
</div>
<% end %>
My qualification model has a scope as:
scope :pending, -> { where(pending: true) }
The problem is, each profile lists all the qualifications. How do I limit this to each profile just listing its own qualifications.
I've tried adding 'Profile' / '@profile' to the view partial in various places, but those attempts just produce errors.
Is there an example for how to do this. I thought rails might know how to do this given the view form for qualifications is nested inside the profiles form.
TAKING TIM'S SUGGESTION
I change the qualifications partial show to:
<% profile.qualifications.pending.order(year_earned: :asc).each do |qualification| %>
<div class="row">
<div class="col-md-12">
<div class="profilequalifications">
<%= qualification.current_study %>
</div>
</div>
</div>
And i change the profiles show page to:
<%= render :partial => 'profiles/qualifications', profile: @profile %>
I get this error:
undefined local variable or method `profile' for #<#:0x007f97ba143030>