【发布时间】:2014-07-06 03:40:33
【问题描述】:
我有一个全新的 Rails 4.1.1 应用程序,我正在其中自定义设计电子邮件。我想让它们显示在新的 Rails 电子邮件预览功能上,所以我做了以下操作:
1) 将以下 sn-p 添加到我的 config/development.rb 文件中:
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
2) 在app/mailers/user_mailer.rb 中创建了我的自定义设计电子邮件UserMailer:
class UserMailer < Devise::Mailer
helper :application # gives access to all helpers defined within `application_helper`.
include Devise::Controllers::UrlHelpers # Optional. eg. `confirmation_url`
layout "notifications_mailer"
end
3) 将config/initializers/devise.rb 更改为包含以下 sn-p:
config.mailer = 'UserMailer'
4) 将UserMailerPreview 类添加到lib/mailer_previews,内容如下:
class UserMailerPreview < ActionMailer::Preview
def confirmation_instructions
UserMailer.confirmation_instructions(User.first, {})
end
def reset_password_instructions
UserMailer.reset_password_instructions(User.first, {})
end
def unlock_instructions
UserMailer.unlock_instructions(User.first, {})
end
end
到目前为止,一切都很好。看起来我做的一切都是正确的。但后来我尝试在 /rails/mailers/user_mailer/confirmation_instructions 路由中查看 confirmation_instructions 电子邮件的预览,我收到以下错误:
undefined method `confirmation_url' for #<#<Class:0x007fa02ab808e0>:0x007fa030fb7e80>
我的confirmation_url.html.erb 模板的代码如下所示:
<%= t("notifications.texts.greeting") + @user.display_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>
我做错了什么?我想我调用confirmation_url 方法的方式有问题。任何人都可以在这里帮助我吗?
【问题讨论】:
-
你在哪里打电话给
confirmation_url?您能否分享出现此错误的相关代码。 -
啊,在视图中。更新了帖子
-
我听从了@steel 的建议,并得到了它的工作。我还必须重新启动服务器才能使更改生效。
标签: ruby-on-rails ruby ruby-on-rails-4 devise