rails 4设计使用电子邮件预览宝石

时间:2014-12-11 07:37:41

标签: ruby-on-rails devise comfortable-mexican-sofa

我想通过rails电子邮件预览宝石通过电子邮件预览设计确认邮件等,并与舒适的墨西哥沙发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>

这里是我的devise.rb

 config.mailer = "DeviseMailer"

这里我的路线文件

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

谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

这是一个Rails错误。在Rails master中修复。现在,您只需重新定义应用内的邮件预览路线即可。有关详细信息,请参阅此处:

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

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