0
0

More than 3 years have passed since last update.

9.7振り返り

Last updated at Posted at 2021-09-07

js呼び出す時にcreateでredirect_to入れて呼び出せなくなった

 def new
    @calender = Calender.new
  end

  def create
    @calender = Calender.new(calender_params)
    @calender.patient_id = current_patient.id
    @calender.save

    #jsの時は↓入れると読み込まれなくなる
    # if @calender.save
    #   redirect_to patient_calenders_path
    # else
    #   render :index
    # end
  end

$('ここの指定が違う')

apprication.js
$(function () {

            ここに違うもの入れてエラーになって表示できない
  $('#calendar_test').fullCalendar({
    selectable: true,
    header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,agendaWeek,agendaDay'
    },

ブラウザでconsoleを使ってエラーを確認する 

console log "run"を走らせてどこまで動くか確認 

引数の指定が違ってエラー                 undefined local variable or method `patient

パスを確認する

/staff/patients/:patient_id/records/new(.:format)

から :patient_idが必要であることがわかるので指定する

@patient = Patient.find(params[:patient_id])

staff/records#new
new_staff_patient_record_path   GET /staff/patients/:patient_id/records/new(.:format)   
staff/records#new
 class Staff::RecordsController < ApplicationController
  def new
    @record = Record.new
    #@patient = Patient.find(params[:id])では情報がとれないというエラー
    #routesでpathを確認  records#new の /staff/patients/:patient_id/records/new(.:format)
    #引数を次のように直す
    @patient = Patient.find(params[:patient_id])
  end

routesのパスが

/staff/ostomies/:ostomy_id/comments(.:format) なら

:ostomy_id  が必要になる

   

/staff/ostomies/:id なら

:id が必要になる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0