Last active
December 16, 2015 03:39
-
-
Save tagrudev/5371199 to your computer and use it in GitHub Desktop.
Followers/Following
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready -> | |
$("#following_option").on "ajax:complete", (evn, data) -> | |
$("#following_option").html(data.responseText) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// users/index.html.haml | |
#following_option | |
- if current_user.follower_of? user | |
= render "users/unfollow", user: user | |
- else | |
= render "users/follow", user: user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// users/_follow.html.haml | |
= button_to user_followees_path(user), remote: true, class: "btn", form_class: "following_option" do | |
%i.icon-user Follow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// users/_unfollow.html.haml | |
= button_to user_followee_path(id: current_user, user_id: user.id), remote: true, method: :delete, class: "btn", form_class: "following_option" do | |
%i.icon-user Unfollow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// followees controller | |
def create | |
current_user.follow @model | |
current_user.save | |
@model.save | |
if request.xhr? | |
return render partial: 'users/unfollow', locals: { user: @model } | |
end | |
end | |
def destroy | |
user = User.where(id: params[:user_id]).first | |
current_user.unfollow user | |
current_user.save | |
user.save | |
if request.xhr? | |
return render partial: 'users/follow', locals: { user: @model } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment