Class: WcoEmail::EmailTemplatesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- WcoEmail::EmailTemplatesController
- Defined in:
- app/controllers/wco_email/email_templates_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #iframe_src ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #show_iframe ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 4 def create :create, WcoEmail::EmailTemplate if params[:photo].present? photo = Wco::Photo.create! params[:photo].permit! params[:template][:photo_id] = photo.id end @tmpl = WcoEmail::EmailTemplate.create params[:template].permit! if @tmpl.persisted? flash[:notice] = 'Success.' if params[:template][:photo].present? if @tmpl.photo.present? @tmpl.photo.update(params[:template][:photo]) else @tmpl.photo = Wco::Photo.create(params[:template][:photo]) end end else flash[:alert] = "Could not create an email template: #{@tmpl.errors..join(', ')}." end redirect_to action: :index end |
#destroy ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 29 def destroy :destroy, WcoEmail::EmailTemplate @tmpl = WcoEmail::EmailTemplate.where({ id: params[:id] }).first || WcoEmail::EmailTemplate.find_by({ slug: params[:id] }) if @tmpl.destroy flash[:notice] = 'Success.' else flash[:alert] = 'Cannot destroy this template.' end redirect_to action: :index end |
#edit ⇒ Object
40 41 42 43 44 45 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 40 def edit @tmpl = @email_template = WcoEmail::EmailTemplate.where({ id: params[:id] }).first :edit, @tmpl @photo = @tmpl.photo || @tmpl.build_photo end |
#iframe_src ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 47 def iframe_src @tmpl = @email_template = WcoEmail::EmailTemplate.where({ id: params[:id] }).first || WcoEmail::EmailTemplate.find_by({ slug: params[:id] }) :iframe_src, @email_template @lead = Lead.find_by({ email: 'poxlovi@gmail.com' }) @ctx = Ctx.new({ email_template: @tmpl, lead_id: @lead.id }) @tmpl_config = OpenStruct.new JSON.parse( @ctx.tmpl[:config_json] ) @utm_tracking_str = { 'cid' => @ctx.lead_id, 'utm_campaign' => @ctx.tmpl.slug, 'utm_medium' => 'email', 'utm_source' => @ctx.tmpl.slug, }.map { |k, v| "#{k}=#{v}" }.join("&") @unsubscribe_url = WcoEmail::Engine.routes.url_helpers.unsubscribes_url({ template_id: @ctx.tmpl.id, lead_id: @lead.id, token: @lead.unsubscribe_token, }) render layout: false end |
#index ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 72 def index :index, WcoEmail::EmailTemplate @templates = WcoEmail::EmailTemplate.all if params[:q] q = URI.decode(params[:q]) @templates = @templates.where({ :slug => /#{q}/i }) end @templates = @templates.order_by( slug: :asc ) if '_index_expanded' == params[:view] @templates = @templates.page( params[:templates_page] ).per( current_profile.per_page ) end render params[:view] || '_index' end |
#new ⇒ Object
91 92 93 94 95 96 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 91 def new @tmpl = WcoEmail::EmailTemplate.new :new, WcoEmail::EmailTemplate @photo = @tmpl.photo || @tmpl.build_photo end |
#show ⇒ Object
98 99 100 101 102 103 104 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 98 def show @tmpl = WcoEmail::EmailTemplate.where({ id: params[:id] }).first @tmpl ||= WcoEmail::EmailTemplate.find_by({ slug: params[:id] }) :show, @tmpl @ctx = @email_context = WcoEmail::Context.new end |
#show_iframe ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 106 def show_iframe @tmpl = WcoEmail::EmailTemplate.where({ id: params[:id] }).first @tmpl ||= WcoEmail::EmailTemplate.find_by({ slug: params[:id] }) :show, @tmpl @ctx = WcoEmail::Context.new({ email_template: @tmpl, lead: Wco::Lead.find_by({ email: 'poxlovi@gmail.com' }), }) eval( @tmpl.config_exe ) @renderer = WcoEmail::ApplicationMailer.renderer ctx: @ctx render layout: false end |
#update ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 123 def update @tmpl = WcoEmail::EmailTemplate.where({ id: params[:id] }).first :update, @tmpl if params[:photo].present? photo = Wco::Photo.create! params[:photo].permit! params[:template][:photo_id] = photo.id end flag = @tmpl.update_attributes( params[:template].permit! ) if flag flash[:notice] = 'Success.' else flash[:alert] = "No luck. #{@tmpl.errors..join(', ')}" end redirect_to action: :edit end |