Class: Fcid::FriendshipsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/fcid/friendships_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
# File 'app/controllers/fcid/friendships_controller.rb', line 16

def create
  Fcid::Friendship.with_session current_user do
    logger.debug current_user.fcid_auth_token
    @user = Fcid::User.find current_user.id 
    @friendship = Fcid::Friendship.new params[:fcid_friendship]
    @friendship.user_id = @user.id
    @success = @friendship.save
  end
  respond_to do |format|

    format.html do
      if @success
        flash[:notice] = "操作成功"
      else
        flash[:error] = @friendship.errors.full_messages.first
      end
      @redirect_to = params[:redirect_to]
      if @redirect_to.blank?
        redirect_to :back
      else
        redirect_to @redirect_to
      end
    end


    format.js do
      render :update do |page|
        page.alert("yes")
      end
    end

  end
end

#destroyObject



60
61
62
63
# File 'app/controllers/fcid/friendships_controller.rb', line 60

def destroy
  friend_id = params[:friend_id]
  @friend = Fcid::User.find params[:friend_id]
end

#indexObject

输出 json 和 xml 或者其他的一些信息 可能得缓存,具体方案得研究



10
11
12
13
14
# File 'app/controllers/fcid/friendships_controller.rb', line 10

def index
  Fcid::Friendship.with_session current_user do
    @friendships = Fcid::Friendship.find :all
  end
end

#newObject



50
51
52
53
54
55
56
57
58
# File 'app/controllers/fcid/friendships_controller.rb', line 50

def new
  friend_id = params[:friend_id]
  @friend = Fcid::User.find params[:friend_id]
  if @friend.friend?(current_user)
    # 已经是朋友了
  else
    @friendship = Fcid::Friendship.new :note=>nil,:friend_id=>friend_id,:user_id=>nil
  end
end