# Probably easy -- data from controller into a database

**URL:** <https://www.ruby-forum.com/t/probably-easy-data-from-controller-into-a-database/75565>\
**Category:** Rails\
**Created:** [November 11, 2006, 12:30am UTC](https://www.ruby-forum.com/t/probably-easy-data-from-controller-into-a-database/75565 "2006-11-11T00:30:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [November 11, 2006, 12:30am UTC](https://www.ruby-forum.com/t/probably-easy-data-from-controller-into-a-database/75565/1 "2006-11-11T00:30:50Z")

</div>

Hi, this is probably a really simple question, but I want to create a  
link that does this when you click it: It enters the ID of the current  
session, and the ID of the user profile page into a database table  
called “friends”. The button basically adds friends to the current  
user.

I’m guessing that the link should look something like:

\<%= link\_to ‘Add as a friend’, :controller =\> ‘users’, :action =\>  
‘addfriend’, :id =\> user.id %\>

I’m obviously new to this and can’t figure out what the action  
‘addfriend’ should look like in the controller so the two id’s can be  
entered into the table. Nothing works, and I feel like I’m just  
stabbing in the dark. Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [November 11, 2006, 3:20am UTC](https://www.ruby-forum.com/t/probably-easy-data-from-controller-into-a-database/75565/2 "2006-11-11T03:20:17Z")

</div>

Hi Dave,

Dave A. wrote:

> Nothing works, and I feel like I’m just  
> stabbing in the dark.

What have you tried? This list can be very helpful. More so, the more  
you  
let us know.

Looking forward…

Bill

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [November 11, 2006, 3:34am UTC](https://www.ruby-forum.com/t/probably-easy-data-from-controller-into-a-database/75565/3 "2006-11-11T03:34:19Z")

</div>

Dave A. wrote:

> :id =\> user.id %\>

hint: what’s user?

---

<div class="post-metadata">

**Author:** ![daveamos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a698b9/32.png) [@daveamos](https://www.ruby-forum.com/u/daveamos)\
**Post date:** [November 11, 2006, 5:14am UTC](https://www.ruby-forum.com/t/probably-easy-data-from-controller-into-a-database/75565/4 "2006-11-11T05:14:21Z")

</div>

Bill W. wrote:

> Dave A. wrote:
> 
> > :id =\> user.id %\>
> 
> hint: what’s user?

Oops, user is a reference to the users table, the id column.

Sorry I didn’t give more information, I assumed creating a controller  
action that enters data into a database was really obvious and I was  
just missing something.

All I’ve tried are variations on controller code generated by scaffold,  
so it starts something like:

def addfriend  
if request.post?  
@friend.save  
end

Beyond that, I don’t know. Also, do I have to put this action in the  
friends controller, since I’m inserting data into the friends database,  
or can I put wherever I want (like the Users controller)?
