redirect_to :action => :index需要跳转到index这个action,然后渲染index.html.erb,额外增加了一次http请求。直接render
"index", :alert => 'Your book was not found!'就把额外的这次请求给免了
render是服务器直接给你页面。
redirect_to是服务器给浏览器地址,浏览器再次请求服务器给自己的哪个地址,跳转。
render是渲染模板
redirect_to是跳转,也就是发送新的请求到某Action
本文解释了Rails中render与redirect_to的区别。render用于直接渲染模板,而redirect_to则发送新的请求到指定Action,涉及两次HTTP请求。使用render可以避免不必要的额外请求。
1014

被折叠的 条评论
为什么被折叠?



