def render_with_layout_and_partials(format)
      # looking for system mail.
      template = MailEngine::MailTemplate.where(:path => "#{controller_path}/#{action_name}", :format => format, :locale => I18n.locale, :partial => false, :for_marketing => false).first
      # looking for marketing mail.
      template = MailEngine::MailTemplate.where(:path => action_name, :format => format, :locale => I18n.locale, :partial => false, :for_marketing => true).first if template.blank?

      # if found db template set the layout and partial for it.
      if template
        related_partial_paths = {}
        # set @footer or @header
        template.template_partials.each do |tmp|
          related_partial_paths["#{tmp.placeholder_name}_path".to_sym] = tmp.partial.path
        end

        # set layout
        render :template => "#{controller_path}/#{action_name}", :layout => "layouts/mail_engine/mail_template_layouts/#{template.layout}", :locals => related_partial_paths
      else
        # if not found db template should render file template
        render(action_name)
     end
    end
def render_with_layout_and_partials(format)
      # looking for system mail.
      template = MailEngine::MailTemplate.where(:path => "#{controller_path}/#{action_name}", :format => format, :locale => I18n.locale, :partial => false, :for_marketing => false).first
      # looking for marketing mail.
      template = MailEngine::MailTemplate.where(:path => action_name, :format => format, :locale => I18n.locale, :partial => false, :for_marketing => true).first if template.blank?

      # if found db template set the layout and partial for it.
      if template
        related_partial_paths = {}
        # set @footer or @header
        template.template_partials.each do |tmp|
          related_partial_paths["#{tmp.placeholder_name}_path".to_sym] = tmp.partial.path
        end

        # set layout
        render :template => "#{controller_path}/#{action_name}", :layout => "layouts/mail_engine/mail_template_layouts/#{template.layout}", :locals => related_partial_paths
      else
        # if not found db template should render file template
        render(action_name)
     end
    end
render template with layout and partials