0

我想通过 rails email preview gem 发送电子邮件预览以获取设计确认邮件等,它与舒适的墨西哥沙发 cms 集成。我需要通过该 cms 编辑邮件内容。Rails 电子邮件预览没有与我舒适的墨西哥沙发 cms 集成,我会尝试我的水平,但对我不起作用。它是如何工作的,我不清楚。有人帮助我

这里是我的 Gemfile

gem 'rails_email_preview', '~> 0.2.28'
gem 'comfortable_mexican_sofa', '~> 1.12.0'

这里我的 config/initializers/rails_email_preview.rb 文件

require 'rails_email_preview'

#= REP hooks and config
# RailsEmailPreview.setup do |config|

#  # hook before rendering preview:
#  config.before_render do |message, preview_class_name, mailer_action|
#    # apply premailer-rails:
#    Premailer::Rails::Hook.delivering_email(message)
#    # or actionmailer-inline-css:
#    ActionMailer::InlineCssHook.delivering_email(message)
#  end
#
#  # do not show Send Email button
# config.enable_send_email = false
#
#  # You can specify a controller for RailsEmailPreview::ApplicationController to inherit    from:
#  config.parent_controller = 'Admin::ApplicationController' # default: '::ApplicationController'
#end

#= REP + Comfortable Mexican Sofa integration
#
# # enable comfortable_mexican_sofa integration:
  require 'rails_email_preview/integrations/comfortable_mexica_sofa'

Rails.application.config.to_prepare do
  # Render REP inside a custom layout (set to 'application' to use app layout, default is REP's own layout)
  # This will also make application routes accessible from within REP:
  # RailsEmailPreview.layout = 'admin'

  # Set UI locale to something other than :en
  # RailsEmailPreview.locale = :de

  # Auto-load preview classes from:
   RailsEmailPreview.preview_classes = Dir[Rails.root.join 'app/mailer_previews/*_preview.rb'].map { |p|
File.basename(p, '.rb').camelize
}
end

这里我的 app/mailer_previews/devise_mailer_preview.rb 文件

class DeviseMailerPreview < ActionMailer::Preview

   def confirmation_instructions
     user = User.first
     DeviseMailer.confirmation_instructions(user)
   end
end

这里我的 app/mailers/devise_mailer.rb 文件

class DeviseMailer < Devise::Mailer
   default from: "from@example.com"

  def confirmation_instructions(user)
    @user = user
    mail to: user.email
  end
end

在这里我的 app/views/devise/confirmations/confirmation_instructions.html.erb

 <%= @user.name %>,

 <p>You can confirm your account email through the link below:</p>

 <p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token =>  @token) %></p>

这是我的设计.rb

 config.mailer = "DeviseMailer"

这是我的路线文件

 mount RailsEmailPreview::Engine, at: '/emails'
 comfy_route :cms_admin, :path => '/admin'

感谢您的帮助!

4

1 回答 1

0

这是一个 Rails 错误。在 Rails 大师中修复。现在你只需要在你的应用程序中重新定义邮件预览路由。有关更多详细信息,请参见:

https://github.com/comfy/comfortable-mexican-sofa/issues/553

https://github.com/rails/rails/blob/b47d8dea25aa4c1b0d02603adc00cf63f2163f21/actionmailer/lib/action_mailer/railtie.rb#L44

于 2014-12-11T14:37:34.070 回答