这是我的控制器中的创建方法(旧方式):
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
语法