前提・実現したいこと
現在Ruby on Railsにてユーザーから管理者へのお問い合わせフォームを作成しています。
お問い合わせ内容を書き込み、送信ボタンを押すと問い合わせ完了ページではなく、Template is missing
というエラーが出てしまいます。
エラーの内容
Missing template inquiry_mailer/received_email with "mailer". Searched in: * "inquiry_mailer"
該当のソースコード
inquiry_controller.rb↓
class InquiryController < ApplicationController def index @inquiry = Inquiry.new render :action => 'index' end def confirm @inquiry = Inquiry.new(inquiry_params) if @inquiry.valid? render :action => 'confirm' else render :action => 'index' end end def thanks @inquiry = Inquiry.new(inquiry_params) InquiryMailer.received_email(@inquiry).deliver render :action => 'thanks' end private def inquiry_params params.require(:inquiry).permit(:name, :email, :message) end end
inquiry.rb↓
class Inquiry include ActiveModel::Model attr_accessor :name, :email, :message validates :name, :presence => {:message => '名前を入力してください'} validates :email, :presence => {:message => 'メールアドレスを入力してください'} end
confirm.html.haml↓
%h1 お問い合わせ内容確認 = form_for @inquiry, :url => inquiry_thanks_path do |f| %table %tr %th 名前 %td = f.hidden_field :name = @inquiry.name %tr %th メールアドレス %td = f.hidden_field :email = @inquiry.email %tr %th お問い合わせ内容 %td = f.hidden_field :message = simple_format(@inquiry.message) = f.submit '送信', class: 'btn btn-primary'
inquiry_mailer.rb↓
class InquiryMailer < ActionMailer::Base default from: "example@example.com" default to: "example@example.com" def received_email(inquiry) @inquiry = inquiry mail(:subject => 'お問い合わせを承りました') end end
その他
八方塞がりなのでどなたかお助けしていただけると幸いです。
自分でも再度調べてみます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。