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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Craig W. (Guest)
on 2006-02-08 21: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(
      :referral_notes,
      :include => [:placement],
      :conditions => ["placement_id = ?", params[:placement_id] ],
      :per_page => 14)
  end

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?

Craig
This topic is locked and can not be replied to.