Rails - Retrieve data from multiple tables
I have read so much about Rails in the past week in the process of trying
to learn it. The problem is when I need something I find it difficult to
recall where I read it! ha ha
I have two models: Guest and Booking where Guests has_many Bookings.
Therefore the Booking model has a guest_id field included.
I would like to retrieve all the booking data and the guest data and
display in a view as one object. I know I have seen a simple solution to
this (in the Rails doc I think) that does just this.
At the moment I'm doing the following in my BookingsController:
@bookings = Booking.all
and in my associated view I have:
<% @bookings.each do |booking| %>
<p><%= booking.id %></p>
<p><%= booking.email %></p> //this does not work as email is in guests
table!!!
<% end %>
but how can I get the linked Guest table included too?
No comments:
Post a Comment