<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-167  評論-65  文章-0  trackbacks-0

    由于最近老是在表單提交后出現沒有反應的現象,發現是在action中的使用render redirect_to的原因,于是就想搞清楚他兩真正的區別在哪里,上一遍的blog也談到了這二者的區別,但是有點淺,

    http://m.tkk7.com/fl1429/archive/2009/03/10/258886.html

    下面從我們的程序實驗開始:

    1,建立controller

    test_controller.rb

    class TestController < ApplicationController

    def test1
    puts 
    "test1A"
    render :action 
    => "test1"
    puts 
    "test1B"
    end

    def test2
      puts 
    "test2A"
      redirect_to  :action 
    => "test1"
    puts 
    "test2B"
    end

    def test3
     puts 
    "test3A"
     redirect_to  :action 
    => "test3"
      puts 
    "test3B"
    end

    end
     

    2,建立view

    在對應的views->test目錄下有test1.rhtml,test2.rhtml,test3.rhtml,內容隨便寫,例如內容都為 hello word

    3,啟動webrick

    到相應的目錄下Ruby script/server

    4,瀏覽器中瀏覽頁面

    (1)頁面test1.rhtml: http://localhost:3000/test/test1

    瀏覽器中直接輸入地址結果是:

    可能是:

    1test1A 
    2test1B
    3 127.0.0.1 - - [12/Mar/2009:18:10:11 中國標準時間] "GET /test/test1 HTTP/1.1" 304 0 - -> /test/test1 
     

    也可能是:

    1127.0.0.1 - - [12/Mar/2009:18:29:50 中國標準時間] "GET /test/test1 HTTP/1.1" 304 0 - -> /test/test1 
    2test1A
    3test1B 

     

    (2)頁面: test2.rhtml http://localhost:3000/test/test2

    結果:

    1test2A 
    2test2B 
    3127.0.0.1 - - [12/Mar/2009:18:11:10 中國標準時間] "GET /test/test2 HTTP/1.1" 302 98 - -> /test/test2 127.0.0.1 - - [12/Mar/2009:18:11:10 中國標準時間] "GET /test/test1 HTTP/1.1" 304 0 - -> /test/test1
    4test1A 
    5test1B 

      還可以發現最后,瀏覽器的地址的變為: http://localhost:3000/test/test1

     

    (3)頁面test3.rhtml  http://localhost:3000/test/test3

    1test3A 
    2test3B 
    3127.0.0.1 - - [12/Mar/2009:18:12:29 中國標準時間] "GET /test/test3 HTTP/1.1" 302 98 - -> /test/test3 
    4test3A 
    5test3B 
    6127.0.0.1 - - [12/Mar/2009:18:12:29 中國標準時間] "GET /test/test3 HTTP/1.1" 302 98 - -> /test/test3

     

    執行效果是死循環.

    由上述實驗得到結論:

    1,無論是render 還是 redirect_to 都是方法體內的內容全部執行完再跳轉,就算跳轉了,方法體內的還是會全部執行的

    2,render 是跳轉到對應的viewrhtml

    3,redirect_to 是跳轉到對應的 action ,所以頁面三執行的效果死循環!







    write by feng
    posted on 2009-03-12 18:48 fl1429 閱讀(1505) 評論(1)  編輯  收藏 所屬分類: Rails

    評論:
    # re: 深刻理解render 和 redirect_to 2013-01-07 09:12 | zyp731
    簡單,明了,好帖。  回復  更多評論
      
    已訪問數:
    free counters
    主站蜘蛛池模板: 暖暖免费日本在线中文| 国产AV无码专区亚洲AV麻豆丫 | 性xxxxx大片免费视频| 久久久青草青青国产亚洲免观| 美女又黄又免费的视频| 国产免费人人看大香伊| 日韩色日韩视频亚洲网站| 午夜国产大片免费观看| 一级毛片在线播放免费| 伊人亚洲综合青草青草久热| sss日本免费完整版在线观看| 亚洲日韩精品无码专区网站 | 99国产精品视频免费观看| 亚洲精品无码久久毛片波多野吉衣| 亚洲xxxx18| 日本大片在线看黄a∨免费 | 日韩亚洲产在线观看| sihu国产精品永久免费| 亚洲最大激情中文字幕| 久久99精品国产免费观看| 亚洲国产片在线观看| 岛国大片免费在线观看| 亚洲AV成人一区二区三区AV| 免费无码中文字幕A级毛片| 亚洲国产精品综合一区在线| 成全高清视频免费观看| 爱情岛论坛免费视频| 亚洲精品无码av人在线观看| 久久午夜羞羞影院免费观看| 国产成人精品日本亚洲专| 亚洲av再在线观看| 最好看的中文字幕2019免费| 亚洲精品一二三区| 亚洲伦乱亚洲h视频| 精品无码免费专区毛片| 精品在线免费视频| 亚洲成AV人片在线播放无码| 成人毛片免费观看视频| a级毛片在线免费看| 亚洲午夜无码久久久久软件| 亚洲伊人久久大香线蕉综合图片|