生徒が先生に相談できるフォームを作り、送信されたら先生のメールアドレス宛に届くというシステムをActionMailerで作ろうとしています。
inquiryのnew actionである入力場面まではうまくいったのです。しかし、inquiry/confirmにurlが飛んだものの、画面がnewのままconfirmに移行していないので(エラー文がでない)どこに記述の誤りがあるか分かっていない状況です。
お力を貸していただければ光栄です。情報に不備がある場合は遠慮なくお申し付けください。
#お問い合わせフォーム resources :teachers do resources :inquiry end post 'inquiry/confirm' => 'inquiry#confirm' # 確認画面 post 'inquiry/thanks' => 'inquiry#thanks' # 送信完了画面
inquiry.rb
class Inquiry < ApplicationRecord include ActiveModel::Model attr_accessor :body belongs_to :teacher belongs_to :user end
class InquiryController < ApplicationController def new # 入力画面を表示 @inquiry = Inquiry.new render :action => 'new' end def confirm # 入力値のチェック @inquiry = Inquiry.new(inquiry_params) if @inquiry.valid? # OK。確認画面を表示 render :action => 'confirm' else # NG。入力画面を再表示 render :action => 'new' end end def thanks # メール送信 @inquiry = Inquiry.new(inquiry_params) InquiryMailer.send_email(@inquiry).deliver # 完了画面を表示 render :action => 'thanks' end private def inquiry_params params.require(:inquiry).permit(:body, :teacher_id, :user_id) end end
inquiry/new.html.erb
<%= form_for @inquiry, :url => inquiry_confirm_path do |f| %> <h1>お問い合わせ</h1> <%= f.text_area :body %> <%= f.submit '確認' %> <% end %>
inquiry/confirm.html.erb
<%= form_for @inquiry, :url => inquiry_thanks_path do |f| %> <h1>お問い合わせ内容<h1> <%= f.hidden_field :body %> <%= simple_format(@inquiry.body) %> <%= f.submit '送信' %> <%= link_to "戻る",new_teacher_inquiry_path(@teacher)%> <% end %>
あなたの回答
tips
プレビュー