0
這是我在我的控制器創建方法(舊的方式):Rails的:respond_with工作不正常時創建行動
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
語法