前提
投稿した内容を編集して、保存を行うエラーが出る
実現したいこと
編集機能の実装
保存に成功するとルートぱす
保存に失敗するとそのページに止まる
条件分岐
発生している問題・エラーメッセージ
https://gyazo.com/57114216e39481526fed4f0584fc5f64
該当のソースコード
prototypes_controller.rb
1class PrototypesController < ApplicationController 2 before_action :set_prototype, only: [:show, :edit] 3 def index 4 @user = current_user.name 5 @prototypes = Prototype.all 6 end 7 8 def new 9 @prototype = Prototype.new 10 end 11 def create 12 Prototype.create(prototype_params) 13 if 14 redirect_to root_path 15 else 16 17 render "new" 18 end 19 def show 20 21 end 22 def edit 23 end 24 25 def update 26 if @prototype.update(prototype_params) 27 redirect_to root_path 28 else 29 render "edit" 30 end 31 end 32 33 34 end 35 36 private 37 def prototype_params 38 params.permit(:title, :concept, :image, :catch_copy).merge(user_id: current_user.id) 39 end 40 def set_prototype 41 @prototype = Prototype.find(params[:id]) 42 end 43 end
edit.html.erb
1<div class="main"> 2 <div class="inner"> 3 <div class="form__wrapper"> 4 <h2 class="page-heading">プロトタイプ編集</h2> 5 <%# 部分テンプレートでフォームを表示する %> 6 <%= render partial: "form", loclals: { prototype: @prototype } %> 7 </div> 8 </div> 9</div>
### 試したこと ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー