Loading twitter status...
/ 14.Mar.2007
Even though the Trac has been up for a week, the plugin hasn’t really been in functional order. Today announces the first real ‘release’ of has_many_friends!
I wrote a pretty big handful of tests for an application I’m working on know and the plugin passed pretty well like. The next step is to extract some of the tests and insert them into the plugin. I really need to figure out a good way to do this because everyone has a different user information and different information that’s required and must be validated, so I’m having a hard time thinking of a good way to implement tests that will validate and be pretty transparent. If anyone out there has some idea’s, let me know. Id love to hear them.
I’m also very open to any suggestions or comments about the plugin in general. Even though adding tests directly to the plugin would be great, it’s the plugin itself that deserves the attention. So have a look, or give it an install and tell me what you think. Let me know what could be done better. Let me know what was terrible about it or what you really liked. I still have a lot to learn and enjoy any feedback you can give. If you wish to jump right in, use the command below..
script/install http://svn.dnite.org/has_many_friends
UPDATE: HowTo (of sorts) has been written and availiable here. Check it out if your having trouble using the has_many_friends plugin.
micro theme by seaofclouds, edited by me, and powered with Mephisto
19 Comments
Thanks for your plugin but the Trac is down now. dev.dnite.org is the same as dnite.org.
Sorry about that. I decided I didn’t really need the Trac’s for the time being. Everything should just link to svn.dnite.org, so I changed the links. They should work now.
Steve,
Just wanted to let you know I posted your plugin to the repository on AgileWebDevelopment.com
http://agilewebdevelopment.com/plugins/has_many_friends
Cheers, David
Ohhhhh – nice – can’t wait to check out!
Hi Steve, I really like your plugin it’s EXACTLY what I was looking for, Thanks. I have one question though….Let’s say I wanted two types of Friends (BestFriend and RegularFriend) associated with the same Friend Class, how could I do this? I was thinking maybe making a has_one association with a child class called BestFriend and Regularfriend and adding your has_many_friends at that level, but I’m not sure if that would work. Please advise if you could, Thanks again. Joe
@joe: hm. i never thought about this. The easiest (and somewhat non-normalized) way of doing things would be to just add a ‘friendship_type’ column to the friendship model that could hold the type of friend. The cool thing about using a relationship model is that you can add attributes to the friendship. You could also do a whole new model for friendship_type and add a ‘has_one friendship_type’ to the friendship model too. Let me know if any of those methods work for ya.
Can you give me some pointers on the best way to make this restful again? I was interested in using your restful friends idea, but that seems to not survived the transition to plugin.
Chuck
Can you give me some pointers on the best way to make this restful again? I was interested in using your restful friends idea, but that seems to not survived the transition to plugin.
Chuck
This seems like a great plugin. Do you have any sample controller methods? Is it possible for you to help me out with this? I am having a difficult time figuring out the controller parts of rails and this plugin. Any help would be wonderful. Thanks in advance.
I’d second lambo4jos ’s comment, I’ve been messing around for ages and can’t get to first base with the controller code
Actually, have written a very dirty add_friend method in my user_controller
def add_friend #dirty code, just to get it working @friend = Friendship.new @friend.user_id = session:user @friend.friend_id = params[:id] @friend.save end
Then in the view
<% @user.pending_friends.each do |u| %> <%= u.login %> <% end %>
I can tell that some people are having problems with this so I’ll go ahead and make a new post that will teach the basics and maybe give some examples about how I implemented it into my restful apps in the very near future. Thanks for the comments, everyone!
Hi… I have done something almost identical although not as a plugin. The main differences is I needed the referenced class to be something other than User so any class can have_many_friends so to speak.
I also wrote this for the friends function, rather than concatenating two lists, seemed more efficient somehow…
Ignore the minor naming differences.
I would also use a sql finder to see if someone is a friend or not rather than loading all my friends into a list and seeing if they are in the list. I believe that maybe more scaleable if someone has a huge number of friends. Also I have the friend_id’s fks indexed which also will help with performance.
Other than minor naming differences it is eerie how similar our two approaches are.
I don’t want to wait till the end of Summer :( , I want it now. Who with me? save your time and join me. ;)
I wrote up a howto (kinda) so those of you who are having trouble using this plugin can check it out and see if it helps you out any. Enjoy!
Hi Steve,
I am using this wonderful plug-in for my development and I have one small query problem that gives me an error, nothing wrong with the plugin but its a custom. requirement:
I need to list user names and pictures of corresponding users and that too by limiting the list to just 5 users.
Heres the controller code:
@friend = User.find(session[:user_id]) @user = User.find(params[:id]) @friends = @user.friends.find(:all, :limit => “5”)
end
Here’s my view code:
<%=image_path url_for( :controller => “user_pics”, :action => “show_thumb”, :id => friendship.user_pic ) %>” />
<%= friendship.name %>
When I write this query I get a wrong argument error.
Please guide me with this task… any help is appreciated.
Cheers
Lukey
@lukey: I’d love to offer some advise but I’d need you to post some more information about the error your receiving. Where are you getting the wrong argument error? Maybe posting a small portion of the error your getting? What method does the error happen on?
Hi Steve,
thanks for the reply and apologies for the delayed reply, well here’s the full error:
wrong number of arguments (2 for 1)
RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace
{RAILS_ROOT}/app/controllers/user_profiles_controller.rb:51:in `find’
{RAILS_ROOT}/app/controllers/user_profiles_controller.rb:51:in `home’
where line number 51 is: @friends = @user.friends.find(:all, :order => “accepted_at desc”, :limit => “2”)
in my view am getting the users name, and picture to be displayed, it works pretty well as long as its just @friends = @user.friends
here’s my method in controller:
def home @user = User.find(session[:user_id]) @users = User.available_users @user_pic = UserPic.find(:first, :conditions => [‘user_id=?’, current_user]) @friend = current_user @friends = @user.friends.find(:all, :order => “accepted_at desc”, :limit => “2”)
end
Just not able to get this right…Thanks a lot in advance for your help…
Cheers
Hi Steve,
I got it, just had to do this sensible thing in my method: :order => “accepted_at desc”, :limit => “3”) + @user.friends_by_me.find(:all, :order => “accepted_at desc”, :limit => “3”)
and vola, it works amazingly…Thanks for this amazing plugin…
Cheers
Leave a Comment