前提
scaffoldコマンドを使い、CRUD処理を行なったところ以下のエラーが発生し新規登録する際に保存することができません。
if @schedule_memo.saveにエラーが出ており、誤字など探してみたのですが自力では解決することができませんでした。
宜しくお願い致します。
#エラーメッセージ
ruby
1NameError in ScheduleMemosController#create 2uninitialized constant ScheduleMemo::Title 3Extracted source (around line #27): 4 5 respond_to do |format| 6 if @schedule_memo.save 7 format.html { redirect_to schedule_memo_url(@schedule_memo), notice: "Schedule memo was successfully created." } 8 format.json { render :show, status: :created, location: @schedule_memo } 9 else 10### 該当のソースコード 11
ソースコード
ruby
1class ScheduleMemosController < ApplicationController 2 before_action :set_schedule_memo, only: %i[ show edit update destroy ] 3 4 # GET /schedule_memos or /schedule_memos.json 5 def index 6 @schedule_memos = ScheduleMemo.all 7 end 8 9 # GET /schedule_memos/1 or /schedule_memos/1.json 10 def show 11 end 12 13 # GET /schedule_memos/new 14 def new 15 @schedule_memo = ScheduleMemo.new 16 end 17 18 # GET /schedule_memos/1/edit 19 def edit 20 end 21 22 # POST /schedule_memos or /schedule_memos.json 23 def create 24 @schedule_memo = ScheduleMemo.new(schedule_memo_params) 25 26 respond_to do |format| 27 if @schedule_memo.save 28 format.html { redirect_to schedule_memo_url(@schedule_memo), notice: "Schedule memo was successfully created." } 29 format.json { render :show, status: :created, location: @schedule_memo } 30 else 31 format.html { render :new, status: :unprocessable_entity } 32 format.json { render json: @schedule_memo.errors, status: :unprocessable_entity } 33 end 34 end 35 end 36 37 # PATCH/PUT /schedule_memos/1 or /schedule_memos/1.json 38 def update 39 respond_to do |format| 40 if @schedule_memo.update(schedule_memo_params) 41 format.html { redirect_to schedule_memo_url(@schedule_memo), notice: "Schedule memo was successfully updated." } 42 format.json { render :show, status: :ok, location: @schedule_memo } 43 else 44 format.html { render :edit, status: :unprocessable_entity } 45 format.json { render json: @schedule_memo.errors, status: :unprocessable_entity } 46 end 47 end 48 end 49 50 # DELETE /schedule_memos/1 or /schedule_memos/1.json 51 def destroy 52 @schedule_memo.destroy 53 54 respond_to do |format| 55 format.html { redirect_to schedule_memos_url, notice: "Schedule memo was successfully destroyed." } 56 format.json { head :no_content } 57 end 58 end 59 60 private 61 # Use callbacks to share common setup or constraints between actions. 62 def set_schedule_memo 63 @schedule_memo = ScheduleMemo.find(params[:id]) 64 end 65 66 # Only allow a list of trusted parameters through. 67 def schedule_memo_params 68 params.require(:schedule_memo).permit(:title_id, :start, :fin, :all, :memo) 69 end 70end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。