# Getting and posting info from database?

**URL:** <https://www.ruby-forum.com/t/getting-and-posting-info-from-database/107190>\
**Category:** Rails\
**Created:** [June 19, 2007, 12:45am UTC](https://www.ruby-forum.com/t/getting-and-posting-info-from-database/107190 "2007-06-19T00:45:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakedgr8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jakedgr8](https://www.ruby-forum.com/u/jakedgr8)\
**Post date:** [June 19, 2007, 12:45am UTC](https://www.ruby-forum.com/t/getting-and-posting-info-from-database/107190/1 "2007-06-19T00:45:42Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![jakedgr8](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jakedgr8](https://www.ruby-forum.com/u/jakedgr8)\
**Post date:** [June 19, 2007, 1:36am UTC](https://www.ruby-forum.com/t/getting-and-posting-info-from-database/107190/2 "2007-06-19T01:36:08Z")

</div>

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 D. 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 F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
