出於某種原因,我的實例變量沒有在這個ActionMailer中設置。其他ActionMailer似乎工作正常。任何想法可能會造成這種情況? UserMailer是一個限制詞perpahps嗎?爲什麼我的實例變量沒有在我的動作郵件的視圖中設置?
使用Rails 3.1
# app/mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default from: 'My Name <[email protected]>'
def registration_confirmation(user)
# Don't send email if we don't have an email address to send it to or the user is already confirmed
return unless user and user.email and not user.confirmed_at
# Set global variable for mail view
@my_message = 'Hello world!'
# Send email
mail(to: "#{user.name} <#{user.email}>", subject: 'Please confirm your email address')
end
end
# app/views/user_mailer/registration_confirmation.text.erb
Hello who? <%= @my_message %> # Simply returns 'Hello who? '