美文网首页ruby on rails
render和redirect_to

render和redirect_to

作者: 五月的约修亚 | 来源:发表于2017-03-10 17:05 被阅读0次
  1. controllermodelviews中都可以使用render

  2. <%= render @users %>会渲染一个_users.html.erb的页面

  3. renderredirect_to

#render 只是寻找"XXX"该页面,并不执行其对应的controller中的action。不会向浏览器发送新的请求,仍然可以使用当前请求的参数和变量
render :action => 'XXX'

#redirect_to 向浏览器发送一个新的请求,跳转到该action
redirect_to :action => 'XXX'
  1. controller中一个方法只能有一个renderredirect_to,并且无论是redirect_to还是render都不会终止当前方法的执行,如果想终止要配合return使用

相关文章

网友评论

    本文标题:render和redirect_to

    本文链接:https://www.haomeiwen.com/subject/whkogttx.html