Skip to content

Instantly share code, notes, and snippets.

@AlexandrBasan
Created June 11, 2015 03:55
Show Gist options
  • Save AlexandrBasan/f5ce819929d5a389048a to your computer and use it in GitHub Desktop.
Save AlexandrBasan/f5ce819929d5a389048a to your computer and use it in GitHub Desktop.
Mailer Viewer inside Rails application
class MailersController < Admin::BaseController
def render_layout
# received params
# params[:mailer_type]
# params[:email_template]
# params[:email_format]
mailer_type = params[:mailer_type].camelize
mailer_template = params[:email_template]
type_class = mailer_type.classify.safe_constantize
case params[:mailer_type]
when 'sample_mailer'
type_class.send(mailer_template(param_1, param_2))
when 'user_mailer'
type_class.send(mailer_template(param_1))
else
type_class.send(mailer_template)
logger.debug "No"
end
respond_to do |format|
format.html { render "#{params[:mailer_type]}/#{params[:email_template]}" }
format.text { render "#{params[:mailer_type]}/#{params[:email_template]}" }
end
end
end
# View email inside Project
match 'email/:mailer_type/:email_template.:email_format', to: 'mailers#render_layout', via: 'get'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment