21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-02 17:00:49 +02:00
chexpire/app/controllers/notifications_controller.rb
Jérémy Lecour 830b978626
Rename Notifications.delay to .interval
From French to English "interval" is a better translation than "delay".
It's supposed to mean a number of days between two dates.
2018-07-02 09:52:49 +02:00

45 lines
1 KiB
Ruby

class NotificationsController < ApplicationController
before_action :authenticate_user!
before_action :set_notification, except: [:create]
def create
check = Check.find(params[:check_id])
@notification = check.notifications.build(notification_params)
authorize @notification
if @notification.save
flash[:notice] = "Your notification has been saved."
redirect_to check_path
else
flash.now[:alert] = "An error occured."
render "checks/edit"
end
end
def destroy
@notification.destroy!
respond_to do |format|
format.js
end
end
private
def set_notification
# joins the check because policy use the check relation
@notification = Notification
.joins(:check)
.find_by!(id: params[:id], check_id: params[:check_id])
authorize @notification
end
def notification_params
params.require(:notification).permit(:channel, :recipient, :interval)
end
def check_path
edit_check_path(check_id: params[:check_id])
end
end