Files
eminuxCRM/app/controllers/mail_templates_controller.rb
T
eminuxandCursor c4e5f289cf
CI / scan_ruby (push) Failing after 11m20s
CI / scan_js (push) Successful in 10m35s
CI / lint (push) Has been cancelled
Commit iniziale di eminuxCRM: CRM Rails con pipeline, campagne email e Docker.
Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-17 23:01:48 +02:00

68 lines
1.9 KiB
Ruby

class MailTemplatesController < ApplicationController
before_action :require_current_project!
before_action :set_template, only: %i[edit update destroy]
def index
@page_title = "Template email"
@mail_templates = MailTemplate.for_project(current_project)
end
def new
@page_title = "Nuovo template"
@mail_template = MailTemplate.new(project: current_project, body_html: default_html, subject: "MatchLiveTV per {{societa}}")
end
def create
@mail_template = MailTemplate.new(template_params)
@mail_template.project ||= current_project
if @mail_template.save
redirect_to mail_templates_path, notice: "Template salvato."
else
@page_title = "Nuovo template"
render :new, status: :unprocessable_entity
end
end
def edit
@page_title = "Modifica template"
end
def update
if @mail_template.update(template_params)
redirect_to mail_templates_path, notice: "Template aggiornato."
else
@page_title = "Modifica template"
render :edit, status: :unprocessable_entity
end
end
def destroy
if @mail_template.mailings.exists? || @mail_template.mailings_as_b.exists?
redirect_to mail_templates_path, alert: "Template già usato in un invio: non si elimina, puoi solo modificarlo."
return
end
@mail_template.destroy!
redirect_to mail_templates_path, notice: "Template eliminato."
end
private
def set_template
@mail_template = MailTemplate.for_project(current_project).find(params[:id])
end
def template_params
params.require(:mail_template).permit(:name, :subject, :body_html)
end
def default_html
<<~HTML
<p>Ciao {{contatto_nome}},</p>
<p>scriviamo a <strong>{{societa}}</strong> ({{regione}}) per presentarti MatchLiveTV.</p>
<p>Possiamo aiutarvi a trasmettere le giovanili in modo semplice.</p>
<p>A presto,<br>Il team MatchLiveTV</p>
HTML
end
end