Class: Newsly::NewslettersController

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

Instance Method Summary collapse

Instance Method Details

#deliverObject



44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/newsly/newsletters_controller.rb', line 44

def deliver
  if params[:answer] == "DELIVER"
    Resque.enqueue(Newsly::NewsletterSender, @newsletter.id, params[:recipient_groups])
    @newsletter.sent = true
    @newsletter.save
    render :text => "NEWSLETTER DELIVERED"
  else
    render :text => "WARNING! Not sent, did you answer correctly?"
  end
end

#deliver_batchObject



55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/newsly/newsletters_controller.rb', line 55

def deliver_batch
  if params[:answer] == "BATCH"
    Resque.enqueue(Newsly::NewsletterBatchSender, @newsletter.id, params[:recipient_group], params[:batch_size])
    @newsletter.batch_sent = true
    @newsletter.save
    render :text => "BATCH DELIVERED"        
  else
    render :text => "WARNING! Not sent, did you answer correctly?"
  end  
end

#destroyObject



66
67
68
69
# File 'app/controllers/newsly/newsletters_controller.rb', line 66

def destroy
  @newsletter.destroy
  redirect_to newsletters_url
end

#indexObject



10
11
12
# File 'app/controllers/newsly/newsletters_controller.rb', line 10

def index
  @newsletters = Newsletter.order('created_at desc').all
end

#newObject



25
26
27
28
# File 'app/controllers/newsly/newsletters_controller.rb', line 25

def new
  @newsletter = Newsly::Newsletter.create(:title => "Nyhetsbrevs rubrik", :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.", :sent => false)
  redirect_to newsletter_url(@newsletter)
end

#send_testObject



38
39
40
41
42
# File 'app/controllers/newsly/newsletters_controller.rb', line 38

def send_test
  if Newsly::Mailer.build_newsletter(@newsletter.id, params[:to], Newsly.test_data).deliver
    render :text => "Okidoki"
  end
end

#showObject



14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/newsly/newsletters_controller.rb', line 14

def show
  if Resque.size(:newsletter) > 0 || Resque.size(:mail) > 0
    @queues_working = true
  end
  @recipient_groups = []
  for group in Newsly.recipient_groups
    group[2] ||= group[1].call(@newsletter.id).count
    @recipient_groups.push(group)
  end
end

#updateObject



30
31
32
33
34
35
36
# File 'app/controllers/newsly/newsletters_controller.rb', line 30

def update
  if @newsletter.update_attributes(params[:newsletter])
    render :text => "Last saved #{distance_of_time_in_words_to_now(Time.now, true)} ago"
  else
    render :text => "Kunde inte sparas"
  end
end