ruby on rails - Has many through stop printing the entire object after loop -
i practicing has_many through stuck when looping through contents. displays whole object , not item want.
models:
class appointment < activerecord::base belongs_to :physician belongs_to :patient end class physician < activerecord::base has_many :appointments has_many :patients, through: :appointments end class patient < activerecord::base has_many :appointments has_many :physicians, through: :appointments end
controller:
class patientscontroller < applicationcontroller def index @patients = patient.all @appointments = appointment.all @physicians = physician.all end def show @patients = physician.find(params[:id]) @appointments = appointment.find(params[:id]) @physicians = physician.find(params[:id]) end end
patients/show.html.erb:
<%= @physicians.patients.each |physician| %> <br><br> <%= physician.name %> <% end %>
after entering random data test following result @ http://localhost:3000/patients/1:
jannie runolfsdottir iii eudora moen [#<patient id: 4, name: "jannie runolfsdottir iii", phone: "356-388-3102 x3079", created_at: "2015-05-14 23:09:36", updated_at: "2015-05-14 23:09:36">, #<patient id: 5, name: "eudora moen", phone: "(372) 713-5045 x3012", created_at: "2015-05-14 23:09:36", updated_at: "2015-05-14 23:09:36">]
i based code views in has_many :through relationship , http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association
the question is, how stop whole object displaying? want names display. behaving used .inspect method.
change beginning of first line <%=
<%
.
the =
tells print object returned, in case of each
whole object.
Comments
Post a Comment