Probably easy -- data from controller into a database

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

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

<%= link_to ‘Add as a friend’, :controller => ‘users’, :action =>
‘addfriend’, :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?


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
let us know.

Looking forward…


Dave A. wrote:

:id => %>

hint: what’s user?

Bill W. wrote:

Dave A. wrote:

: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

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)?