Skip to content

Instantly share code, notes, and snippets.

@krisf
Created April 20, 2012 00:20
Show Gist options
  • Select an option

  • Save krisf/2424980 to your computer and use it in GitHub Desktop.

Select an option

Save krisf/2424980 to your computer and use it in GitHub Desktop.

Revisions

  1. krisf revised this gist Apr 20, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original 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
    current_user.follow(@user) ? redirect_to root_url : redirect_to @user
    end
    end

  2. krisf revised this gist Apr 20, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Theirs:
    #Theirs:

    class UsersController < ApplicationController
    def follow
    @@ -11,7 +11,7 @@ def follow
    end
    end

    Mine:
    #Mine:

    class UsersController < ApplicationController
    def follow
    @@ -20,7 +20,7 @@ def follow
    end
    end

    Theirs:
    #Theirs:

    class User < ActiveRecord::Base
    has_many :followings
    @@ -33,7 +33,7 @@ def follow(user)
    end
    end

    Mine:
    #Mine:

    class User < ActiveRecord::Base
    has_many :followings
  3. krisf revised this gist Apr 20, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.rb
    Original 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
    current_user.follow @user ? redirect_to root_url : redirect_to @user
    end
    end

  4. krisf created this gist Apr 20, 2012.
    44 changes: 44 additions & 0 deletions gistfile1.rb
    Original 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