cirandas.net

ref: master

app/controllers/my_profile/friends_controller.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class FriendsController < MyProfileController

  protect 'manage_friends', :profile

  def index
    @suggestions = profile.suggested_profiles.of_person.enabled.includes(:suggestion).limit(per_page)
    if is_cache_expired?(profile.manage_friends_cache_key(params))
      @friends = profile.friends.order(:name)
        .paginate(:per_page => per_page, :page => params[:npage])
    end
  end

  def remove
    @friend = profile.friends.find(params[:id])
    if request.post? && params[:confirmation]
      Friendship.remove_friendship(profile, @friend)
      redirect_to :action => 'index'
    end
  end

  def suggest
    @suggestions = profile.suggested_profiles.of_person.enabled.includes(:suggestion).limit(per_page)
  end

  def remove_suggestion
    @person = profile.suggested_people.find_by(identifier: params[:id])
    redirect_to :action => 'suggest' unless @person
    if @person && request.post?
      profile.remove_suggestion(@person)
      @suggestions = profile.suggested_profiles.of_person.enabled.includes(:suggestion).limit(per_page)
      render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => @suggestions, :collection => :friends_suggestions, :per_page => params[:per_page] || per_page }
    end
  end

  def connections
    @suggestion = profile.suggested_profiles.of_person.enabled.find_by(suggestion_id: params[:id])
    if @suggestion
      @tags = @suggestion.tag_connections
      @profiles = @suggestion.profile_connections
    else
      redirect_to :action => 'suggest'
    end
  end

  protected

  class << self
    def per_page
      12
    end
  end
  def per_page
    self.class.per_page
  end

end