Skip to content

Commit

Permalink
Remove rand() ordering clause (fails in SQLite)
Browse files Browse the repository at this point in the history
  • Loading branch information
wapcaplet committed Jun 28, 2011
1 parent 589358e commit add9775
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions app/controllers/friendships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@ class FriendshipsController < BaseController

def index
@body_class = 'friendships-browser'
@user = (params[:id] ||params[:user_id]) ? User.find((params[:id] || params[:user_id] )): Friendship.find(:first, :order => "rand()").user
@friendships = Friendship.find(:all, :conditions => ['user_id = ? OR friend_id = ?', @user.id, @user.id], :limit => 40, :order => "rand()")
@users = User.find(:all, :conditions => ['users.id in (?)', @friendships.collect{|f| f.friend_id }])

@user = (params[:id] ||params[:user_id]) ? User.find((params[:id] || params[:user_id] )): Friendship.find(:first).user
@friendships = Friendship.find(:all, :conditions => ['user_id = ? OR friend_id = ?', @user.id, @user.id], :limit => 40)
@users = User.find(:all, :conditions => ['users.id in (?)', @friendships.collect{|f| f.friend_id }])

respond_to do |format|
format.html
format.xml { render :action => 'index.rxml', :layout => false}
format.html
format.xml { render :action => 'index.rxml', :layout => false}
end
end

def deny
@user = User.find(params[:user_id])
@user = User.find(params[:user_id])
@friendship = @user.friendships.find(params[:id])

respond_to do |format|
if @friendship.update_attributes(:friendship_status => FriendshipStatus[:denied]) && @friendship.reverse.update_attributes(:friendship_status => FriendshipStatus[:denied])
flash[:notice] = :the_friendship_was_denied.l
format.html { redirect_to denied_user_friendships_path(@user) }
else
format.html { render :action => "edit" }
end
end
end
end

def accept
@user = User.find(params[:user_id])
@user = User.find(params[:user_id])
@friendship = @user.friendships_not_initiated_by_me.find(params[:id])

respond_to do |format|
if @friendship.update_attributes(:friendship_status => FriendshipStatus[:accepted]) && @friendship.reverse.update_attributes(:friendship_status => FriendshipStatus[:accepted])
flash[:notice] = :the_friendship_was_accepted.l
format.html {
redirect_to accepted_user_friendships_path(@user)
format.html {
redirect_to accepted_user_friendships_path(@user)
}
else
format.html { render :action => "edit" }
Expand All @@ -47,81 +47,81 @@ def accept
end

def denied
@user = User.find(params[:user_id])
@user = User.find(params[:user_id])
@friendships = @user.friendships.find(:all, :conditions => ["friendship_status_id = ?", FriendshipStatus[:denied].id], :page => {:current => params[:page]})

respond_to do |format|
format.html
end
end


def accepted
@user = User.find(params[:user_id])
@user = User.find(params[:user_id])
@friend_count = @user.accepted_friendships.count
@pending_friendships_count = @user.pending_friendships.count

@friendships = @user.friendships.accepted.find :all, :page => {:size => 12, :current => params[:page], :count => @friend_count}

respond_to do |format|
format.html
end
end

def pending
@user = User.find(params[:user_id])
@user = User.find(params[:user_id])
@friendships = @user.friendships.find(:all, :conditions => ["initiator = ? AND friendship_status_id = ?", false, FriendshipStatus[:pending].id])

respond_to do |format|
format.html
end
end

def show
@friendship = Friendship.find(params[:id])
@user = @friendship.user

respond_to do |format|
format.html
end
end


def create
@user = User.find(params[:user_id])
@friendship = Friendship.new(:user_id => params[:user_id], :friend_id => params[:friend_id], :initiator => true )
@friendship.friendship_status_id = FriendshipStatus[:pending].id
@friendship.friendship_status_id = FriendshipStatus[:pending].id
reverse_friendship = Friendship.new(params[:friendship])
reverse_friendship.friendship_status_id = FriendshipStatus[:pending].id
reverse_friendship.friendship_status_id = FriendshipStatus[:pending].id
reverse_friendship.user_id, reverse_friendship.friend_id = @friendship.friend_id, @friendship.user_id

respond_to do |format|
if @friendship.save && reverse_friendship.save
UserNotifier.deliver_friendship_request(@friendship) if @friendship.friend.notify_friend_requests?
format.html {
flash[:notice] = :friendship_requested.l_with_args(:friend => @friendship.friend.login)
flash[:notice] = :friendship_requested.l_with_args(:friend => @friendship.friend.login)
redirect_to accepted_user_friendships_path(@user)
}
format.js { render( :inline => :requested_friendship_with.l+" #{@friendship.friend.login}." ) }
format.js { render( :inline => :requested_friendship_with.l+" #{@friendship.friend.login}." ) }
else
flash.now[:error] = :friendship_could_not_be_created.l
@users = User.find(:all)
format.html { redirect_to user_friendships_path(@user) }
format.js { render( :inline => "Friendship request failed." ) }
format.js { render( :inline => "Friendship request failed." ) }
end
end
end

def destroy
@user = User.find(params[:user_id])
@user = User.find(params[:user_id])
@friendship = Friendship.find(params[:id])
Friendship.transaction do
Friendship.transaction do
@friendship.destroy
@friendship.reverse.destroy
end
respond_to do |format|
format.html { redirect_to accepted_user_friendships_path(@user) }
end
end
end

end

0 comments on commit add9775

Please sign in to comment.