On 5 November 2015 at 10:48, Deepak Sharma <[email protected]> wrote:
> # Patient
>
> class Patient < ActiveRecord::Base
>   belongs_to :department
>   belongs_to :consultant
> end
>
> # Consultant
>
> class Consultant < ActiveRecord::Base
>   has_many :patients
> end
>
> # Department
>
> class Department < ActiveRecord::Base
>   has_many :patients
> end

So there is only one consultant for a patient.  Assuming that is the
information you want then something like

     <% @departments.each do |d| %>
       <% d.patients.each do |patient| %>
         <tr>
           <td><%= patient.patient_name %></td>
           <td><%= d.name %></td>
            <td><%= patient.consultant.name %></td>

I am a little surprised that this is not already clear to you.  I
assume that you have worked right through railstutorial.org as I have
suggested to you several times previously.  Have you done that?  If
not then please do so, it will save you from getting stuck on simple
issues and having to waste both your time asking such questions and my
time answering them.

Cheers

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLv-EzPO5h%3DYLRxy3qww3pmOuSwh0AEoqegjWc5%3Da52%3D-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to