views:

15

answers:

1

I'm attempting to build a proper RESTful approach at removing a friend while looking at their profile page. I've used this Railscast episode as the basis for my self referential Friendship model, but his approach differs in that he has a page listing all the friendships, with a delete button next to each one. Since he's already iterating through friendships, he has the friendship entry ID handy and can pass it into the delete link just fine.

Details of my implementation are here. The part that I'm trying to construct is this one in the view:

<p><%= link_to 'Remove friend', friendships_path(current_user.friendships.where(:friend_id => @user).last), :method => :delete %></p>

My main stumbling block is how to look up the friendship model ID for the current profile page that a given user is looking up. Obviously, I can just attach the friend's user_id to the delete link and then have the delete action of the friend controller look up the join table entry to delete it, but that doesn't seem to follow the proper RESTful model. What should my friendship_path parameter look like?

The approach above seems somewhat convoluted and the link URL it generates contains a period in it, which looks weird (and it doesn't work either):

<p><a href="/friendships.2" data-method="delete" rel="nofollow">Remove friend</a></p>
A: 

I'd expect the URL to signify deleting a friendship with an individual, not the action join table Id or whatever. I.e. if the user you no longer want a friend relationship with has ID 10, I would expect the URL to look something like /friend/10 and a delete to that location would remove the friendship, not the user ID.

calmh
I don't think that's the proper REST approach though. It's the friendship I want to delete, so I make the appropriate delete action call to the friendship controller, and it gets the friendship ID. Just like if you were deleting product, you'd call the delete method and pass in the product ID.
Joost Schuur
Maybe you're right - I'm thinking more of the target ("friend") in the context of the current user, as implicitly indicating the friendship. But that might be an ugly approach.
calmh
I'm leaning towards giving up on attempting towards being RESTful as much as possible at this point. And by 'leaning to', I mean I am.
Joost Schuur