Class: FriendshipsController

Inherits:
BaseController show all
Defined in:
app/controllers/friendships_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#advertise, #cache_action?, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index

Methods included from BaseHelper

#add_friend_link, #ajax_spinner_for, #avatar_for, #block_to_partial, #box, #city_cloud, #clippings_link, #commentable_url, #container_title, #excerpt_with_jump, #flash_class, #forum_page?, #is_current_user_and_featured?, #jumbotron, #last_active, #more_comments_links, #page_title, #paginating_links, #possesive, #profile_completeness, #render_jumbotron, #render_widgets, #rounded, #search_posts_title, #search_user_posts_path, #show_footer_content?, #tag_auto_complete_field, #time_ago_in_words, #time_ago_in_words_or_date, #topnav_tab, #truncate_words, #truncate_words_with_highlight, #widget

Methods included from LocalizedApplication

#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale

Methods included from AuthenticatedSystem

#login_by_token, #update_last_seen_at

Instance Method Details

#acceptObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/friendships_controller.rb', line 20

def accept
  @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)
      }
    else
      format.html { render :action => "edit" }
    end
  end
end

#acceptedObject



46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/friendships_controller.rb', line 46

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

  @friendships = @user.friendships.accepted.page(params[:page]).per(12)

  respond_to do |format|
    format.html
  end
end

#createObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/friendships_controller.rb', line 77

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
  reverse_friendship = Friendship.new
  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.friendship_request(@friendship).deliver if @friendship.friend.notify_friend_requests?
      format.html {
        flash[:notice] = :friendship_requested.l_with_args(:friend => @friendship.friend.)
        redirect_to accepted_user_friendships_path(@user)
      }
      format.js {@text = "#{:requested_friendship_with.l} #{@friendship.friend.}."}
    else
      flash.now[:error] = :friendship_could_not_be_created.l
      format.html { redirect_to user_friendships_path(@user) }
      format.js {@text = "#{:friendship_request_failed.l}."}
    end
  end
end

#deniedObject



36
37
38
39
40
41
42
43
# File 'app/controllers/friendships_controller.rb', line 36

def denied
  @user = User.find(params[:user_id])
  @friendships = @user.friendships.where("friendship_status_id = ?", FriendshipStatus[:denied].id).page(params[:page])

  respond_to do |format|
    format.html
  end
end

#denyObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/friendships_controller.rb', line 6

def deny
  @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

#destroyObject



101
102
103
104
105
106
107
108
109
110
111
# File 'app/controllers/friendships_controller.rb', line 101

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

#pendingObject



58
59
60
61
62
63
64
65
# File 'app/controllers/friendships_controller.rb', line 58

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

  respond_to do |format|
    format.html
  end
end

#showObject



67
68
69
70
71
72
73
74
# File 'app/controllers/friendships_controller.rb', line 67

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

  respond_to do |format|
    format.html
  end
end