Class: MyForum::PrivateMessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/my_forum/private_messages_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user!, #current_user, #current_user_groups, #current_user_id, #forum_time, #is_admin?, #new_pm_count

Instance Method Details

#createObject



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
# File 'app/controllers/my_forum/private_messages_controller.rb', line 30

def create
  @pm = PrivateMessage.new
  recipient = begin
    User.(params[:private_message].delete(:recipient))
  rescue
    #TODO send notification to admin
    nil
  end

  unless recipient
    @pm.errors.add(:base, t('.cant_find_recipient'))
    render :new
    return
  end

  @pm.recipient_id    = recipient.id
  @pm. = recipient.
  @pm.sender_id       = current_user_id
  @pm.    = current_user.
  @pm.assign_attributes(pm_params)

  UserMailer.pm_notification(recipient, current_user).deliver_now if @pm.save

  flash[:notice] = I18n.t('my_forum.pm.sent')

  redirect_to action: :index
end

#deletedObject



21
22
23
# File 'app/controllers/my_forum/private_messages_controller.rb', line 21

def deleted

end

#inboxObject



13
14
15
# File 'app/controllers/my_forum/private_messages_controller.rb', line 13

def inbox

end

#indexObject



8
9
10
11
# File 'app/controllers/my_forum/private_messages_controller.rb', line 8

def index
  @private_messages = PrivateMessage.inbox_for(current_user).paginate(per_page: 16, page: params[:page])
  render :inbox
end

#newObject



25
26
27
28
# File 'app/controllers/my_forum/private_messages_controller.rb', line 25

def new
  @pm = PrivateMessage.new
  @reply_pm = PrivateMessage.find(params[:reply_for_id]) if params[:reply_for_id]
end

#outboxObject



17
18
19
# File 'app/controllers/my_forum/private_messages_controller.rb', line 17

def outbox

end

#showObject



58
59
60
61
# File 'app/controllers/my_forum/private_messages_controller.rb', line 58

def show
  @pm = PrivateMessage.inbox_for(current_user).find(params[:id])
  @pm.update!(unread: false)
end