Hi everyone,
I’m building a little recipe-sharing site and I want users to add others
as “friends”, just like outlined in the Rails Recipes book, chapter 18.
I created the user model just like in the book:
has_and_belongs_to_many :friends,
:class_name => “User”,
:join_table => “friendships”,
:association_foreign_key => “friend_id”,
:foreign_key => “user_id”
The only difference is that my join table is called “Friendships”, and
my Person table is “Users”.
My problem is that I can’t figure out how to insert friendships into the
friendship table. In the book he does it in the console, and I don’t
know how to do it in my app.
In every user profile I have:
<%= link_to ‘Add as a friend’, :controller => ‘users’, :action =>
‘friendify’ %>
I just don’t know how to make my friendify action add the user_id and my
current_user as friends in the friendship table. Any ideas?
Thanks so much!