Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

sample of how to use acts_as_follower with rails3 and ajax

View FollowsController.rb
1 2 3 4 5 6 7 8 9 10 11 12 13
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
View FollowsController.rb
1 2 3 4 5 6 7
<% 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 %>
View FollowsController.rb
1 2 3
$('#follow_user').html('<%= escape_javascript(render :partial => "shared/follow_user", :locals => {:user => @user}) %>');
 
#jQuery
View FollowsController.rb
1 2 3
$('#follow_user').html('<%= escape_javascript(render :partial => "shared/follow_user", :locals => {:user => @user}) %>');
 
#jQuery
View FollowsController.rb
1 2 3 4 5 6 7
...
 
resources :users, :only => [:index, :show] do
resources :follows, :only => [:create, :destroy]
end
 
...
View FollowsController.rb
1 2 3 4 5
<% if user_signed_in? %>
<div id="follow_user">
<%= render :partial => "shared/follow_user", :locals => {:user => @user} %>
</div>
<% end %>
View FollowsController.rb
1 2 3 4 5 6 7 8 9 10
class User < ActiveRecord::Base
...
 
acts_as_follower
acts_as_followable
...
end

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.