Ok so I have a profile page on my website. In the database I have all the information about the user, including the username, first and last names, passwords, and descriptions, locations, and any other information. Now what code would I need, to get the data from the table "users" depending on who is logged into the system. Say "Bob" is logged in, how do I get ruby to look for "Bob" in users and, let''s say, display the user''s current location and/or First and Last name. And don''t be too harsh, I''m completely new to RoR and still trying to get stuff to "make sense". -- 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 -~----------~----~----~----~------~----~------~--~---
andrew.ohnstad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-18 23:34 UTC
Re: Getting and posting info from database?
If you are completley new to Ror I would suggest reading some of the thousands of tutorials on the web, or one of the several books about Rails that are out now (Agile Web Development With Rails 2nd Edition is the crowd favorite). The answers to your questions aren''t that simple. How does the application know what user is logged in? You can search your database like this... @user=User.find_by_username(Bob) Where ''username'' is the column in the DB you want to search and ''Bob'' is what to search for. The entire row will be returned as an array @user, so then you can use @user.location @user.first_name @user.last_name or @user.whatever Usually developers store the user_id in the session information, so you can do something like @user = User.find(session[:id]) I hope this gets you on the right path, but you really need to start reading up... :) On Jun 18, 6:45 pm, Jake Fake <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ok so I have a profile page on my website. In the database I have all > the information about the user, including the username, first and last > names, passwords, and descriptions, locations, and any other > information. Now what code would I need, to get the data from the table > "users" depending on who is logged into the system. Say "Bob" is logged > in, how do I get ruby to look for "Bob" in users and, let''s say, display > the user''s current location and/or First and Last name. > > And don''t be too harsh, I''m completely new to RoR and still trying to > get stuff to "make sense". > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---