【发布时间】:2017-09-01 07:54:00
【问题描述】:
我有使用另一个 Rails API 进行数据库操作的 rails 5.0.1 应用程序(应用程序 1)。 应用 1 没有使用活动记录,而是使用 flexirest 进行 Api 调用。
当调用 create 或 update 方法时,所有数据都以 json 格式发送到 rails api。 我希望当 api 抛出任何错误时,它应该在救援块中被捕获,并且用户在提交点击之前输入的数据应该在救援之后使用渲染:编辑(用于更新)或渲染:新(用于创建)进行渲染
这是我的代码
def update
respond_to do |format|
begin
if @booking.update({id: @booking.booking.id, booking: booking_params})
format.html { redirect_to excel_front_innstats_path, notice: display_notice(t("label.detailed_reservation.reservation")) }
else
format.html { render :edit }
end
rescue => e
#here assign the booking object with user entered data,
#so that the form will not loose the data
#if exception occurs
flash_error_message(:error, e.result)
format.html { render :edit }
end
end
end
【问题讨论】:
-
添加你的代码的结果,你的想法和结果的区别
-
你有什么问题?
-
@artgb 现在编辑用数据库中的数据呈现视图,我想要用户提交的表单中的数据。
-
您必须更改视图才能使用预订参数
-
在我的编辑视图中,我使用这个
标签: ruby-on-rails ruby ruby-on-rails-5 rest-client