【发布时间】:2018-12-01 05:00:47
【问题描述】:
脚手架生成的这段代码最终打印了两次相同的消息,我无法让它停止。
def update
respond_to do |format|
if @indi.update(indi_params)
puts("message about to be shown to us by the system")
format.html { redirect_to @indi, notice: 'Indi was successfully updated.' }
format.json { render :show, status: :ok, location: @indi }
else
format.html { render :edit }
format.json { render json: @indi.errors, status: :unprocessable_entity }
end
end
end
它在网页中打印两次成功消息。
【问题讨论】:
-
在你的网页视图中你是否渲染了两次通知
-
不是故意的。这是服务器的一些控制台输出。系统将向我们显示消息 重定向到localhost:3000/indis/48 已完成 302 发现 5ms (ActiveRecord: 0.0ms) 开始 GET "/indis/48" ... IndisController 处理#show as HTML 参数: {"id" =>“48”}用户负载(0.0ms)选择“用户”。*从Indi负载(0.0毫秒)选择“indis”。*从“indis”到“indis”。“id”=?限制 ? [["id", 48]... 渲染 indis/show.html.erb w/in layouts/application 渲染 indis/show.html.erb w/iin layouts/application
-
[此代码在 application.html.erb
-
视图顶部有
-
所以你做了两次,对吧。我在警报成功以及 top of view 中都看到了它。这不是双重渲染的问题吗?
标签: ruby-on-rails activerecord scaffold