如何從ActionMailer :: Preview訪問view_context?如何從ActionMailer預覽中訪問視圖助手或view_context?
class EventMailerPreview < ActionMailer::Preview
def notify_user
EventMailer.notify_user user: stripe_detail.subscription.user,
plan: event.data.object.lines.data[0].plan.name,
amount: view_context.number_to_currency(event.data.object.total/100.0, locale: :us),
date: Time.at(event.data.object.lines.data[0].period.start).to_date
未定義局部變量或方法`view_context」爲#< EventMailerPreview:0x0000001567a448 >
http://guides.rubyonrails.org/action_mailer_basics.html#previewing-emails
http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_to_currency
我也嘗試不view_context
和我還試圖helpers.
。
我結束了剛剛推原值一路下跌到視圖並調用'number_to_currency'助手那裏。但是,真的,如果我想要內聯呈現純文本呢?我怎麼稱呼那個幫手? – Chloe