开发者

Haml + ActionMailer - Rails?

I'm trying to use ActionMail开发者_Go百科er without Rails in a project, and I want to use Haml for the HTML email templates. Anyone have any luck getting this configured and initialized so that the templates will be found and rendered? I'm currently getting errors like:

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


Looks like the issue is that without the full Rails stack, Haml doesn't completely load, specifically the Haml::Plugin class. Adding require 'haml/template/plugin' after the normal require 'haml' line seems to solve the problems.


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


Not necessary in Rails -- but since you're using ActionMailer without Rails -- did you specify ActionMailer::Base.register_template_extension('haml')?


I'm seeing a similar issue and am using ActionMailer 3.0.3. register_template_extension does not exist in ActionMailer 3.

I'm using Sinatra. I've got mailer.rb (below) in APP_ROOT/lib and the views are located in APP_ROOT/views/mailer. This sends an email with a subject, the body is blank 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜