Haml + ActionMailer - Rails?

I am trying to use ActionMailer without Rails in a project, and I want to use Haml for HTML email templates. Someone is lucky that this is configured and initialized so that the templates are found and displayed? I am currently getting errors, for example:

ActionView::MissingTemplate: Missing template new_reg/daily_stats/full with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en]} in view paths "/home/petersen/new_reg/lib/new_reg/mailers/views"

To clarify, this is ActionMailer 3.0.4

+3
source share
4 answers

It seems that the problem is that without a full Rails Haml stack, the Haml :: Plugin class, in particular, does not load completely. Adding require 'haml/template/plugin'after a normal line require 'haml'seems to solve the problems.

+6
source

require 'haml/template/plugin'in the configure do block, along with ActionMailer::Base.view_paths = "./views/"did it for me (Sinatra)

+1

Rails - ActionMailer Rails - ActionMailer::Base.register_template_extension('haml')?

0

, ActionMailer 3.0.3. register_template_extension ActionMailer 3.

I use Sinatra. I have mailer.rb (below) in APP_ROOT / lib and the views are in APP_ROOT / views / mailer. It sends an email with the subject, the body is empty, though.

require 'action_mailer'
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.view_paths = File.dirname(__FILE__)+"/../views/"
ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => 'exmaple.com',
  :user_name            => 'user@exmaple.com',
  :password             => 'password',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

class Mailer < ActionMailer::Base

   def new_comment_notifier(post,comment)
      @post = post
      @comment = comment

      mail(:to => "user@example.com",
           :subject => "new comment on: #{post.title}")
   end
end
0
source

Source: https://habr.com/ru/post/1793125/


All Articles