views:

17

answers:

0

Hy,

my controller example:


class FriendsController < ApplicationController

  before_filter :authorize, :except => [:friends]


  ##############
  ##############
  ## REQUESTS ##
  ##############
    ##############


    ##################
    # GET MY FRIENDS #
    ##################
    # Get my friends.
    def friends
      @friends = @my_profile.friends.paginate({:page => params[:page], :per_page => 3})
      @profile = @my_profile
    end


    ###################
    # REMOVED FRIENDS #
    ###################
    # Get my deleted friends.
    def removed_friends
      @removed_friends = @my_profile.friends('removed_friends', params[:page])
    end


    ###################
    # PENDING FRIENDS #
    ###################
    # Friend requests made by other profiles to me.
    def pending_friends
      @pending_friends = @my_profile.friends('pending_friends', params[:page])
    end


    ############################
    # REJECTED PENDING FRIENDS #
    ############################
    # Rejected friend requests made by other profiles to me.
    def rejected_pending_friends
      @rejected_pending_friends = @my_profile.friends('rejected_pending_friends', params[:page])
    end


    #####################
    # REQUESTED FRIENDS #
    #####################
    # The friend requests I've sent to others profiles.
    def requested_friends
      @requested_friends = @my_profile.friends('requested_friends', params[:page])
    end


    #############################
    # DELETED REQUESTED FRIENDS #
    #############################
    # The requests I've sent to others 
    # profiles and then canceled.
    def deleted_requested_friends
     @deleted_requested_friends = @my_profile.friends('deleted_requested_friends', params[:page])
    end





    #############
    #############
    ## ACTIONS ##
    #############
    #############


    ##########################
    # ADD FRIENDSHIP REQUEST #
    ##########################
    # Add a friendship request.
    def add_friendship_request
      friendship = @my_profile.add_friendship_request(params[:profile_id])
      render :json => friendship
    end


    #############################
    # REMOVE FRIENDSHIP REQUEST #
    #############################
    # Removes a friendship request I've done.
    def remove_friendship_request
      friendship = @my_profile.remove_friendship_request(params[:profile_id])
      render :json => friendship
    end


    ######################
    # PROCESS FRIENDSHIP #
    ######################
    # Process friendship: accept or reject a friend.
    # This will make a new friend or
    # will make a new rejected pending friend.
    def process_friendship
      friendship = @my_profile.process_friendship(params[:profile_id].to_i, params[:accepted].to_i)
      render :json => friendship
    end


    ###################
    # REMOVE A FRIEND #
    ###################
    # Remove a friend from my friends by id.
    def remove_friend
      friendship = @my_profile.remove_friend(params[:profile_id])
      render :json => friendship
   end


  end