Created
April 20, 2012 00:20
-
-
Save krisf/2424980 to your computer and use it in GitHub Desktop.
Revisions
-
krisf revised this gist
Apr 20, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def follow class UsersController < ApplicationController def follow @user = User.find(params[:id]) current_user.follow(@user) ? redirect_to root_url : redirect_to @user end end -
krisf revised this gist
Apr 20, 2012 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #Theirs: class UsersController < ApplicationController def follow @@ -11,7 +11,7 @@ def follow end end #Mine: class UsersController < ApplicationController def follow @@ -20,7 +20,7 @@ def follow end end #Theirs: class User < ActiveRecord::Base has_many :followings @@ -33,7 +33,7 @@ def follow(user) end end #Mine: class User < ActiveRecord::Base has_many :followings -
krisf revised this gist
Apr 20, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def follow class UsersController < ApplicationController def follow @user = User.find(params[:id]) current_user.follow @user ? redirect_to root_url : redirect_to @user end end -
krisf created this gist
Apr 20, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ Theirs: class UsersController < ApplicationController def follow @user = User.find(params[:id]) if current_user.follow(@user) redirect_to root_url else redirect_to @user end end end Mine: class UsersController < ApplicationController def follow @user = User.find(params[:id]) current_user.follow(@user) ? redirect_to root_url : redirect_to @user end end Theirs: class User < ActiveRecord::Base has_many :followings def follow(user) unless followings.where(:followed_user_id => user.id).present? followings.create(:followed_user => user) else false end end end Mine: class User < ActiveRecord::Base has_many :followings def follow(user) self.followings.create(:followed_user => user) unless self.followings.where(:followed_user_id => user.id).present? end end