Class: Manage::MessagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Manage::MessagesController
- Defined in:
- app/controllers/manage/messages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #datatable ⇒ Object
- #deliver ⇒ Object
- #destroy ⇒ Object
- #duplicate ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #live_preview ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
27 28 29 30 31 |
# File 'app/controllers/manage/messages_controller.rb', line 27 def create @message = Message.new() @message.save respond_with(:manage, @message) end |
#datatable ⇒ Object
11 12 13 |
# File 'app/controllers/manage/messages_controller.rb', line 11 def datatable render json: BulkMessageDatatable.new(view_context) end |
#deliver ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/manage/messages_controller.rb', line 43 def deliver if @message.automated? flash[:notice] = "Automated messages cannot be manually delivered. Only bulk messages can." return redirect_to (@message) end if @message.status != "drafted" flash[:notice] = "Message cannot be re-delivered" return redirect_to end @message.update_attribute(:queued_at, Time.now) BulkMessageWorker.perform_async(@message.id) flash[:notice] = "Message queued for delivery" redirect_to (@message) end |
#destroy ⇒ Object
38 39 40 41 |
# File 'app/controllers/manage/messages_controller.rb', line 38 def destroy @message.destroy respond_with(:manage, @message) end |
#duplicate ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/manage/messages_controller.rb', line 70 def duplicate = @message.dup .update_attributes( delivered_at: nil, started_at: nil, queued_at: nil, name: "Copy of #{@message.name}" ) .save redirect_to (.reload) end |
#edit ⇒ Object
24 25 |
# File 'app/controllers/manage/messages_controller.rb', line 24 def edit end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/manage/messages_controller.rb', line 7 def index respond_with(:manage, Message.all) end |
#live_preview ⇒ Object
63 64 65 66 67 68 |
# File 'app/controllers/manage/messages_controller.rb', line 63 def live_preview body = params[:body] || '' = Message.new(body: body) email = Mailer.(nil, current_user.id, ) render html: email.body.raw_source.html_safe end |
#new ⇒ Object
19 20 21 22 |
# File 'app/controllers/manage/messages_controller.rb', line 19 def new @message = Message.new respond_with(:manage, @message) end |
#preview ⇒ Object
58 59 60 61 |
# File 'app/controllers/manage/messages_controller.rb', line 58 def preview email = Mailer.(@message.id, current_user.id) render html: email.body.raw_source.html_safe end |
#show ⇒ Object
15 16 17 |
# File 'app/controllers/manage/messages_controller.rb', line 15 def show respond_with(:manage, @message) end |
#update ⇒ Object
33 34 35 36 |
# File 'app/controllers/manage/messages_controller.rb', line 33 def update @message.update_attributes() respond_with(:manage, @message) end |