render與redirect_to頁面顯示

1.redirect_to要向服務器重新發送請求,示例代碼如下:
redirect_to :action => 'show', :id => 5 
redirect_to "http://www.rubyonrails.org/"
redirect_to "/images/2.jpg"


回到上一次訪問的頁面:
redirect_to :back


2.render是渲染頁面,並沒有向服務器重新發送請求,即render僅僅渲染了一個新的模板,而沒有執行相應的action。
(1)直接渲染出文本:
render :text => string

(2)直接調用某個action的模板,action_name方法在當前controller裏:
render :action => action_name

(3)調用某個action的模板,action_name方法不在當前controller裏:
render :action => action_name,:controller=>'.......'

(4)默認的的render, 相當於render(:action => self)
render
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章