0
0

More than 3 years have passed since last update.

Mailer viewでヘルパーメソッドを使用する

Posted at

Mailer viewでヘルパーを使いたい

郵便番号にハイフンをいれてくれるメソッド

application_helper.rb
def format_zipcode_include_hyphen(zipcode)
    zipcode.include?('-') ? zipcode : zipcode.insert(3,'-')
end

mailer viewでいきなり使用するとエラーになった。

application_mailer.rb

application_mailer.rb
class ApplicationMailer < ActionMailer::Base
  add_template_helper(ApplicationHelper)
end

と記述する

view

mailer.ftml.slim
p #{format_zipcode_include_hyphen(zipcode)}

でうまくいきました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0