繁体   English   中英

在Rails中渲染和redirect_to

[英]Render and redirect_to in rails

我刚刚在测验中回答了一个问题,问题如下:

以下哪项是关于render和redirect_to的无效语句?

  • render不发送新请求,但redirect_to会发送
  • redirect_to不发送新请求,但是render
  • render不会导致当前动作停止执行
  • redirect_to不会导致当前动作停止执行

我选择了选项1作为答案,但结果是错误的。 我在线检查了一下,发现该链接清楚地表明redirect_to向浏览器发送了新请求:

render和redirect_to之间有一个重要的区别:render将告诉Rails应该使用哪个视图(使用您可能已经发送过的相同参数),但是redirect_to向浏览器发送一个新请求。

备选方案二将是正确的答案,明确指出:下列哪项是无效的陈述

如您所知并知道redirect_to发送一个新请求,但是在选项中它说不发送,因此它变成无效的语句 ,您的答案应该是

redirect_to doesn't send a new request but render does

注意:

Kindly read question properly and understand it first before give the answer..

我想您错过了问题中的invalid单词, 正确答案将是选项4

redirect_to will not cause the current action to stop executing

选项1 render doesn't send a new request but redirect_to does有效,因为redirect_to将get请求发送至类型为get的操作,但是render仅渲染view ,而与其他action无关

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM