---
title: "render与redirect_to页面显示"
author: "tntyao"
date: "2014-04-23T06:59:28Z"
tags: []
categories: ["互联网"]
slug: "render-redirect-to"
draft: false
lastmod: "2014-04-23T06:59:28Z"
id: 2052940
url: "https://tntyao.iteye.com/blog/2052940"
---

1.redirect_to要向服务器重新发送请求，示例代码如下：
Ruby代码  收藏代码

    redirect_to :action => 'show', :id => 5   
    redirect_to "http://www.rubyonrails.org/"   
    redirect_to "/images/2.jpg"  



回到上一次访问的页面：
Ruby代码  收藏代码

    redirect_to :back  



2.render是渲染页面，并没有向服务器重新发送请求，即render仅仅渲染了一个新的模板，而没有执行相应的action。
（1）直接渲染出文本：
Ruby代码  收藏代码

    render :text => string  


（2）直接调用某个action的模板，action_name方法在当前controller里：
Ruby代码  收藏代码

    render :action => action_name  


（3）调用某个action的模板，action_name方法不在当前controller里：
Ruby代码  收藏代码

    render :action => action_name,:controller=>'.......'  


（4）默认的的render, 相当于render(:action => self）
Ruby代码  收藏代码

    render