これが私のコントローラーの作成方法です(古い方法):
def create
@athlete = Athlete.find(params[:video][:athlete_id])
@video = Video.new(params[:video])
if @athlete.can_add_another_video? && @video.save
flash[:notice] = "Successfully created"
PandaWorker.perform_async(@video.id)
log_activity(@video.logging_information)
else
flash[:notice] = @video.errors.full_messages.to_sentence
end
respond_with @video, location: athlete_profile_showcase_path
end
新しい方法:
def create
@athlete = Athlete.find(params[:video][:athlete_id])
@video = Video.new(params[:video])
if @athlete.can_add_another_video? && @video.save
flash[:notice] = "Successfully created"
PandaWorker.perform_async(@video.id)
log_activity(@video.logging_information)
respond_with @video, location: athlete_profile_showcase_path
else
flash[:notice] = @video.errors.full_messages.to_sentence
redirect_to athlete_profile_showcase_path
end
end
上記のコードの最初の部分は、ビデオ オブジェクトの保存が行われない場合に失敗します。VideosController#new
指定した場所をたどるのではなく、メソッドにリダイレクトしようとします。明らかに最初の方法は間違っていますが、その理由はわかりません。どんな助けでも大歓迎です!respond_with
まだ構文を完全に理解しようとしています