Class: Nisetegami::TemplatesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Nisetegami::TemplatesController
- Defined in:
- app/controllers/nisetegami/templates_controller.rb
Instance Method Summary collapse
Instance Method Details
#actions ⇒ Object
18 19 20 |
# File 'app/controllers/nisetegami/templates_controller.rb', line 18 def actions render json: [''] + Nisetegami.mapping.actions(params[:mailer]) end |
#destroy ⇒ Object
35 36 37 38 39 40 |
# File 'app/controllers/nisetegami/templates_controller.rb', line 35 def destroy templates = Template.where(id: params[:template_ids]) template_names = templates.map(&:name).join(', ') templates.destroy_all redirect_to templates_path, notice: t('nisetegami.templates.destroyed', templates: template_names) end |
#edit ⇒ Object
22 23 24 |
# File 'app/controllers/nisetegami/templates_controller.rb', line 22 def edit @template = Template.find(params[:id]) end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/nisetegami/templates_controller.rb', line 7 def index @templates = Template.recent params[:enabled] = params[:enabled] == 'true' ? true : false unless params[:enabled].blank? %w(enabled mailer mailer_action).each do |attr| @templates = @templates.where((attr == 'mailer_action' ? 'action' : attr) => params[attr]) unless params[attr].blank? end %w(name subject from reply_to cc bcc).each do |attr| @templates = @templates.where(["#{attr} LIKE ?", "%#{params[attr]}%"]) unless params[attr].blank? end end |
#test ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/nisetegami/templates_controller.rb', line 42 def test template = Template.find(params[:id]) = unless params[:recipient] =~ Nisetegami.email_re {alert: t('nisetegami.templates.wrong_email')} else template.(params[:recipient], params[:template]).deliver {notice: t('nisetegami.templates.test_email_delivered')} end redirect_to edit_template_path(template), end |
#update ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/controllers/nisetegami/templates_controller.rb', line 26 def update @template = Template.find(params[:id]) if @template.update_attributes(params[:template]) redirect_to templates_path, notice: t('nisetegami.templates.updated', template: @template.name) else render action: :edit end end |