前提
Ruby on Rails で投稿アプリケーションを作成しています。
実現したいこと
新規投稿をする際にフォームに内容を入力しデータが保存された場合はトップページへ遷移し保存されなかった場合は再度新規投稿ページに遷移させたいのですが、保存されなかった場合でもトップページへ戻ってしまします。
Sequel Proでデータの保存に対しては確認できたのですが(バリデーションがかかっているかなど)他のどこが問題のある箇所なのかがわかりません。
ご教授頂けますでしょうか。。
該当のソースコード
prototype contorollerです。
ruby
1class PrototypesController < ApplicationController 2 def index 3 end 4 5 def new 6 @prototype = Prototype.new 7 8 end 9 10 def create 11 if 12 Prototype.create(prototype_params) 13 redirect_to root_path 14 else 15 render :new 16 end 17 end 18 19 20 private 21 22 def prototype_params 23 params.require(:prototype).permit(:title, :catch_copy, :concept, :image).merge(user_id: current_user.id) 24 end 25end
遷移させたいnew.html.erbです。
ruby
1<div class="main"> 2 <div class="inner"> 3 <div class="form__wrapper"> 4 <h2 class="page-heading">新規プロトタイプ投稿</h2> 5 <%# 部分テンプレートでフォームを表示する %> 6 <%= render 'prototypes/form' %> 7 </div> 8 </div> 9</div>
回答2件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。