Class: WcoEmail::EmailTemplatesController
- Inherits:
-
ApplicationController
- Object
- Wco::ApplicationController
- 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
5 6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 5 def create :create, WcoEmail::EmailTemplate @template = WcoEmail::EmailTemplate.create params[:template].permit! if @template.persisted? flash[:notice] = 'Success.' else flash[:alert] = "Could not create an email template: #{@template.errors.full_messages.join(', ')}." end redirect_to action: :index end |
#destroy ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 16 def destroy :destroy, WcoEmail::EmailTemplate @template = WcoEmail::EmailTemplate.where({ id: params[:id] }).first || WcoEmail::EmailTemplate.find_by({ slug: params[:id] }) if @template.destroy flash[:notice] = 'Success.' else flash[:alert] = 'Cannot destroy this template.' end redirect_to action: :index end |
#edit ⇒ Object
27 28 29 30 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 27 def edit @tmpl = @email_template = WcoEmail::EmailTemplate.where({ id: params[:id] }).first :edit, @tmpl end |
#iframe_src ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 32 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: '[email protected]' }) @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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 57 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
76 77 78 79 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 76 def new @new_email_template = WcoEmail::EmailTemplate.new :new, WcoEmail::EmailTemplate end |
#show ⇒ Object
81 82 83 84 85 86 87 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 81 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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 89 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: '[email protected]' }), }) eval( @tmpl.config_exe ) @renderer = WcoEmail::ApplicationMailer.renderer ctx: @ctx render layout: false end |
#update ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/wco_email/email_templates_controller.rb', line 106 def update @template = WcoEmail::EmailTemplate.where({ id: params[:id] }).first :update, @template flag = @template.update_attributes( params[:template].permit! ) if flag flash[:notice] = 'Success.' else flash[:alert] = "No luck. #{@template.errors.full_messages.join(', ')}" end redirect_to action: :edit end |