Class: IshManager::EmailContextsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- IshManager::EmailContextsController
- Defined in:
- app/controllers/ish_manager/email_contexts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #do_send ⇒ Object
- #edit ⇒ Object
- #iframe_src ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #summary ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 9 def create @ctx = ::Ish::EmailContext.new params[:ctx].permit! @tmpl = ::Ish::EmailTemplate.find @ctx.email_template_id @ctx.from_email ||= @tmpl.from_email @ctx.subject ||= @tmpl.subject :create, @ctx if @ctx.save flash[:notice] = 'Saved.' redirect_to action: 'show', id: @ctx.id return else # flash[:alert] = "Could not save: #{@ctx.errors.full_messages.join(', ')}" flash[:alert] = ['Could not save:'] + @ctx.errors. render action: :new return end end |
#destroy ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 29 def destroy @ctx = Ish::EmailContext.find params[:id] :destroy, @ctx flag = @ctx.destroy if flag flash[:notice] = 'Destroyed the email context' else flash[:alert] = 'Could not destroy email context' end redirect_to action: :index end |
#do_send ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 41 def do_send @ctx = ::Ish::EmailContext.find params[:id] :do_send, @ctx flash[:notice] = 'Scheduled a single send - v2' @ctx.send_at = Time.now @ctx.save redirect_to action: 'index' end |
#edit ⇒ Object
52 53 54 55 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 52 def edit @ctx = ::Ish::EmailContext.find params[:id] :edit, @ctx end |
#iframe_src ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 57 def iframe_src @ctx = @email_context = Ish::EmailContext.find params[:id] :iframe_src, @ctx @tmpl = @email_template = @ctx.email_template @lead = @ctx.lead @body = @ctx.body render layout: false end |
#index ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 68 def index :index, ::Ish::EmailContext @ctxs = ::Ish::EmailContext.all if params[:notsent] @ctxs = @ctxs.where( sent_at: nil ) else @ctxs = @ctxs.where( :sent_at.ne => nil ) end if params[:lead_id] @lead = Lead.find params[:lead_id] @ctxs = @ctxs.where( to_email: @lead.email ) end end |
#new ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 84 def new :new, ::Ish::EmailContext @tmpl = @email_template = Ish::EmailTemplate.where( slug: params[:template_slug] ).first || Ish::EmailTemplate.where( id: params[:template_slug] ).first || Ish::EmailTemplate.new attrs = {} if @tmpl attrs = @tmpl.attributes.slice( :subject, :body, :from_email ) end @ctx = ::Ish::EmailContext.new({ email_template: @tmpl }.merge(attrs)) end |
#show ⇒ Object
96 97 98 99 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 96 def show @ctx = @email_context = ::Ish::EmailContext.find( params[:id] ) :show, @ctx end |
#summary ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 101 def summary :summary, Ish::EmailContext @results = Ish::EmailContext.summary puts! @results, 'r' # headers["Content-Type"] ||= 'text/csv' respond_to do |format| format.html # show.html.erb format.csv do render layout: false end end end |
#update ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/controllers/ish_manager/email_contexts_controller.rb', line 117 def update @ctx = ::Ish::EmailContext.find params[:id] :update, @ctx if @ctx.update_attributes params[:ctx].permit! flash[:notice] = 'Saved.' redirect_to action: 'edit', id: @ctx.id return else flash[:alert] = "Could not save: #{@ctx.errors..join(', ')}" render action: :edit return end end |