Forum: Ruby on Rails Getting and posting info from database?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
4fb768311b3974b994dbf17bfc4c79ef?d=identicon&s=25 Jacob J. (jakedgr8)
on 2007-06-19 00:45
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".
744b6438d1457d332d1a8d431cc2b641?d=identicon&s=25 (Guest)
on 2007-06-19 01:36
(Received via mailing list)
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...


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 <>
This topic is locked and can not be replied to.