Class: Proclaim::SubscriptionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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/proclaim/subscriptions_controller.rb', line 23

def create
	@subscription = Subscription.new(subscription_params)

	authorize @subscription

	if antispam_params[:answer] == antispam_params[:solution]
		respond_to do |format|
			if @subscription.save
				format.html {
					redirect_to subscription_path(@subscription.token),
					            notice: "Thanks for subscribing! You should "\
					                    "receive a confirmation email soon."
				}
			else
				format.html { render :new }
			end
		end
	else
		@subscription.errors.add(:base,
		                         "Antispam question wasn't answered "\
		                         "correctly")
		respond_to do |format|
			format.html { render :new }
		end
	end
end

#destroyObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/proclaim/subscriptions_controller.rb', line 50

def destroy
	authorize @subscription
	@subscription.destroy

	respond_to do |format|
		format.html {
			if current_author
				redirect_to subscriptions_path,
			               notice: "Subscription was successfully destroyed."
			else
				redirect_to posts_path,
			               notice: "Successfully unsubscribed. Sorry to "\
			                       "see you go!"
			end
		}
	end
end

#indexObject



9
10
11
12
# File 'app/controllers/proclaim/subscriptions_controller.rb', line 9

def index
	@subscriptions = policy_scope(Subscription).order(:comment_id, :name)
	authorize Subscription
end

#newObject



14
15
16
17
# File 'app/controllers/proclaim/subscriptions_controller.rb', line 14

def new
	@subscription = Subscription.new
	authorize @subscription
end

#showObject



19
20
21
# File 'app/controllers/proclaim/subscriptions_controller.rb', line 19

def show
	authorize @subscription
end