Hello.
I''ve run into a slight problem with extracint data from a table where
one field matches that of the same field of another table.
In my user controller I have:
[CODE]
def login
@fname = params[:fname]
@lname = params[:lname]
end
[/CODE]
And I have this line at the top of the form in the login.rhtml file:
[CODE]
<%= start_form_tag :action => ''showbookings'' :id =>
@fname, @lname %>
[/CODE]
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.
I appreciate the help.
Hussein.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hello again, I got this far: In showbookings.rhtml [CODE] <p>Your Bookings</p> <% @user.bookings.each do |bookings| %> <%= bookings.from %> <%= bookings.to %> <%= bookings.dep_date %> <%= bookings.class %> <% end %> <p>Your Flights</p> <% @bookings.flights.each do |flights| %> <%= flights.from %> <%= flights.destination %> <%= flights.dep_time %> <%= flights.arr_time %> <%= flights.duration %> <%= flights.class %> <% end %> [/CODE] 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). Hussein. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
1) 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? 2) 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---