Class: Newsly::NewslettersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Newsly::NewslettersController
- Defined in:
- app/controllers/newsly/newsletters_controller.rb
Instance Method Summary collapse
- #deliver ⇒ Object
- #deliver_batch ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #send_test ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#deliver ⇒ Object
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_batch ⇒ Object
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 |
#destroy ⇒ Object
66 67 68 69 |
# File 'app/controllers/newsly/newsletters_controller.rb', line 66 def destroy @newsletter.destroy redirect_to end |
#index ⇒ Object
10 11 12 |
# File 'app/controllers/newsly/newsletters_controller.rb', line 10 def index @newsletters = Newsletter.order('created_at desc').all end |
#new ⇒ Object
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) end |
#send_test ⇒ Object
38 39 40 41 42 |
# File 'app/controllers/newsly/newsletters_controller.rb', line 38 def send_test if Newsly::Mailer.(@newsletter.id, params[:to], Newsly.test_data).deliver render :text => "Okidoki" end end |
#show ⇒ Object
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 |
#update ⇒ Object
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 |