In the bookings controller I will have a def showbookings, and a
corresponding showbookings.rhtml file.
What I want to do is show all bookings (contents of the records) where
the fname and lname column match user.fname and user.lname (from the
users table).
I can do it in SQL:
SELECT * FROM Bookings
WHERE fname = users.fname AND lname = users.lname
But I’m not sure how to implement this in Rails, both as a controller
method and to output the info.
Can’t work how to link to match the fname and lname between users and
bookings, and then to match from and to from bookings to flights (second
ruby block).
fname and lname are probably not the best identifiers for logging in
because of the chance for duplication. Then I have to log in as Bob
Smith2 or Jane Doel337 in order to be unique. How about a unique email
address?
I would set up your models like this (pseudocode):
Users
has many flights through reservations conditions “confirmed = TRUE”
Reservations (or Bookings)
belongs to users, flights
Flight
has many users through reservations conditions “confirmed = TRUE”
Then it is easy to access users from flights with @flight.users or @user.flights
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.