Flash uniformity done in a bunch of files

This commit is contained in:
Aditya Chatterjee 2016-03-01 18:58:41 +05:30
parent 1e9f4b514c
commit 598606547e
9 changed files with 37 additions and 39 deletions

View file

@ -2,26 +2,24 @@ class SubscriptionsController < ApplicationController
before_filter :authenticate_user!
load_resource :conference, find_by: :short_title
load_and_authorize_resource only: [:create, :destroy], through: :conference
add_flash_types :error
add_flash_types :alert
def create
@subscription = current_user.subscriptions.build(conference_id: @conference.id)
if @subscription.save!
flash[:notice] = "You have been subscribed to receive email notifications for #{@conference.short_title}."
redirect_to root_path
redirect_to root_path, notice: "You have been subscribed to receive email notifications for #{@conference.short_title}."
else
flash[:error] = subscription.errors.full_messages.to_sentence
redirect_to root_path
redirect_to root_path, error: subscription.errors.full_messages.to_sentence
end
end
def destroy
@subscription = current_user.subscriptions.find_by(conference_id: @conference.id)
if @subscription.destroy
flash[:notice] = "You have been unsubscribed and now you will not be receiving email notifications for #{@conference.short_title}."
redirect_to root_path
redirect_to root_path, notice: "You have been unsubscribed and now you will not be receiving email notifications for #{@conference.short_title}."
else
flash[:error] = @subscription.errors.full_messages.to_sentence
redirect_to root_path
redirect_to root_path, error: @subscription.errors.full_messages.to_sentence
end
end
end