Instantly share code, notes, and snippets.

Embed
What would you like to do?
sample of how to use acts_as_follower with rails3 and ajax
<% unless user == current_user %>
<% if current_user.following?(user) %>
<%= button_to("Un-Follow #{user.nickname}", user_follow_path(user.to_param, current_user.get_follow(user).id), :method => :delete, :remote => true) %>
<% else %>
<%= button_to("Follow #{user.nickname}", user_follows_path(user.to_param), :remote => true) %>
<% end %>
<% end %>
$('#follow_user').html('<%= escape_javascript(render :partial => "shared/follow_user", :locals => {:user => @user}) %>');
#jQuery
$('#follow_user').html('<%= escape_javascript(render :partial => "shared/follow_user", :locals => {:user => @user}) %>');
#jQuery
class FollowsController < ApplicationController
def create
@user = User.find(params[:user_id])
current_user.follow(@user)
end
def destroy
@user = User.find(params[:user_id])
current_user.stop_following(@user)
end
end
...
resources :users, :only => [:index, :show] do
resources :follows, :only => [:create, :destroy]
end
...
<% if user_signed_in? %>
<div id="follow_user">
<%= render :partial => "shared/follow_user", :locals => {:user => @user} %>
</div>
<% end %>
class User < ActiveRecord::Base
...
acts_as_follower
acts_as_followable
...
end
@amritdeep

This comment has been minimized.

amritdeep commented Apr 17, 2014

If we want implement it with mongodb then How can we do it ?

@RailsCod3rFuture

This comment has been minimized.

RailsCod3rFuture commented Jul 7, 2015

Can you update this solution for Rails 4 please?

@tugi93

This comment has been minimized.

tugi93 commented Apr 24, 2017

Does it work with MongoDB?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment