Rails中render和redirect_to页面显示的用法
今天写代码的时候遇到页面跳转的问题,所以查了render 和redirect_to的异同及用法,render 和redirect_to 都是执行页面跳转,并且写在这两个方法后面的语句仍然会被执行。
1.render:简单的页面渲染,可以指定渲染的页面或布局文件,但是不会发出请求,只根据函数参数渲染页面,不会执行action函数,不会重新加载服务器中的数据。render的用法如下:
(1)直接渲染出文本:
render(:text => string)
render(:action => action_name)
render :action => action_name,:controller=>'.......'
render(:file => path, [:use_full_path => true|false])
render()
redirect_to :action => 'edit', :id => 7redirect_to "http://dachuan212.iteye.com/"redirect_to "/images/1.jpg" redirect_to :back