Forum: Ruby on Rails foreign table references...a new twist

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-08 20:51
(Received via mailing list)
I thought I was on top of them all, but found another one that has me
completely stumped.

table referral_notes
  belongs_to: placement

table placements
  has_many: referral_notes

  def list_rfn
    @placement = Placement.find(:all) # possibly unnecessary
    @referral_note = ReferralNote.find(:all,
      :include => [:placement],
      :conditions => ["placement_id = ?", params[:placement_id] ])
    @referral_note_pages, @referral_notes = paginate(
      :include => [:placement],
      :conditions => ["placement_id = ?", params[:placement_id] ],
      :per_page => 14)

list view (possible multiple records). The main object is the
'placement_id' (there's only 1).

If I have a looped structure, I can make this work but it repeats the
placement record 1 time for each referral_note...

<% for referral_note in @referral_notes %>
  <%=h (referral_note.placement.client.wholename) %>
  <%=h (referral_note.note_date) %>
<% end %>

but if I take the first line out of the loop...

<%=h (referral_note.placement.client.wholename) %>
<% for referral_note in @referral_notes %>
  <%=h (referral_note.note_date) %>
<% end %>

it errors - not having a definition for 'referral_note.'
so I try
<%=h (@referral_note.placement.client.wholename) %>

and I still get error...
NoMethodError in Referral_notes#list_rfn
Showing app/views/referral_notes/list_rfn.rhtml where line #16 raised:

undefined method `placement' for #<Array:0xb7a9d904>

Extracted source (around line #16):

16:     <td><%=h (@referral_note.placement.client.wholename) %></td>

as if it lacks knowledge of the relationship for 'placement'

and I have had too many issues working with the 'many' relationships of
referral_notes in the placement controller and have settled on the
thinking that relationships are easiest when working in the controller
that 'belongs_to' side of the relationship.

how/why does it not understand the relationship placement here?

This topic is locked and can not be replied to.