前提
Ruby on Rails で投稿アプリケーションを作成しています。
実現したいこと
新規投稿をする際にフォームに内容を入力しデータが保存された場合はトップページへ遷移し保存されなかった場合は再度新規投稿ページに遷移させたいのですが、保存されなかった場合でもトップページへ戻ってしまします。
Sequel Proでデータの保存に対しては確認できたのですが(バリデーションがかかっているかなど)他のどこが問題のある箇所なのかがわかりません。
ご教授頂けますでしょうか。。
該当のソースコード
prototype contorollerです。
ruby
1class PrototypesController < ApplicationController2 def index3 end4 5 def new6 @prototype = Prototype.new7 8 end9 10 def create11 if12 Prototype.create(prototype_params)13 redirect_to root_path 14 else15 render :new16 end17 end18 19 20 private21 22 def prototype_params23 params.require(:prototype).permit(:title, :catch_copy, :concept, :image).merge(user_id: current_user.id)24 end25end
遷移させたい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>

0 コメント