Class: SubscriberController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/subscriber_controller.rb

Overview

Mailing list management

This is to add or remove subscribers

Instance Method Summary collapse

Instance Method Details

#subscribeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/subscriber_controller.rb', line 7

def subscribe
  @elt = Elt.find params[:id]
  @person = Person.find(session[:person_id])

if @person
	if @elt.subscribers.include?(@person)
		Subscription.find_by_person_id_and_elt_id(@person.id, @elt.id).destroy
		logger.info yellow { "User #{@person.name} unsubscribed from #{@elt.subject}..." }
	elsif @elt.all_recipients.include?(@person)
		elt2 = @elt
		elt2 = elt2.parent until elt2.subscribers.include?(@person)
		Subscription.find_by_person_id_and_elt_id(@person.id, elt2.id).destroy
		logger.info yellow { "User #{@person.name} unsubscribed from #{elt2.subject}..." }
	else
		@elt.subscriptions.create :person => @person, :filter => filter
		logger.info yellow { "User #{@person.name} subscribed to #{@elt.id} with filter #{filter}..." }
	end
else
	puts "Not logged in!"
	#render :inline => "First you need to login... it's easy, type a pseudo with at least 3 characters. Then OK"
	flash.now[:error] = 'First you need to login!'
end
render :partial => '/elt/list/subscribers'
end