Class: UserNotificationsController

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

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#is_current_user?

Instance Method Details

- (Object) create



9
10
11
12
13
14
15
# File 'app/controllers/user_notifications_controller.rb', line 9

def create
  if current_user.user_notifications.create(params[:user_notification])
    redirect_to root_path, notice: t(:message_successfully_sent)
  else
    render :new
  end
end

- (Object) destroy



17
18
19
20
21
22
23
24
# File 'app/controllers/user_notifications_controller.rb', line 17

def destroy
  @user = User.find(params[:user_id])
  @user_notification = @user.user_notifications.find(params[:id])
  authorize! :manage, @user_notification
  @user_notification.delete
  @user.save
  redirect_to notifications_path, notice: t(:notification_successfully_deleted)
end

- (Object) emails



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/user_notifications_controller.rb', line 26

def emails
  respond_to do |format|
     format.json { 
       render :json => User.any_of({ name: /#{params[:q]}/i }, { email: /#{params[:q]}/i })
                           .only(:email,:name)
                           .map{ |user| 
                             [
                               :id =>user., 
                               :name => user.name + " (#{user.})"
                             ]
                            }
                           .flatten
     }
   end
end

- (Object) new



5
6
7
# File 'app/controllers/user_notifications_controller.rb', line 5

def new
  @user_notification = current_user.user_notifications.build()
end