【发布时间】:2015-08-26 08:56:35
【问题描述】:
我需要做条件检查是否渲染这个或那个。
用respond_to 块包装条件检查是否很好?
喜欢
respond_to do |format|
if @applicant.user_id.nil?
# Some logic
format.js
format.html { redirect_to applicant_path(params[:id]) }
else
format.json { render json: {message: t('_applicants.flash.applicant_already_assigned')}, status: 400 }
end
end
或
我将在 if..else 内有多个 respond_to 块
喜欢
if @applicant.user_id.nil?
# Some logic
respond_to do |format|
format.js
format.html { redirect_to applicant_path(params[:id]) }
end
else
respond_to do |format|
format.json { render json: {message: t('_applicants.flash.applicant_already_assigned')}, status: 400 }
end
end
推荐的最佳方法是什么?
【问题讨论】:
标签: ruby-on-rails ruby controller action response