av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Rubyrails頁面跳轉(zhuǎn)知識一點通

Ruby語言可以為我們簡便靈活的實現(xiàn)許多功能需求。很多編程人員都開始將目光投向了這項解釋型語言。今天我們在這里為大家介紹有關(guān)Ruby rails頁面跳轉(zhuǎn)的一些實現(xiàn)技巧。#t#

目前創(chuàng)新互聯(lián)已為近1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、革吉網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

Ruby rails頁面跳轉(zhuǎn)代碼如下:

  1. if @user.update_attributes
    (:password => params
    [:user][:password]) 
  2. flash[:notice] = '密碼修改完成' 
  3. redirect_to :action => 'index' 
  4. else 
  5. redirect_to :action => 
    'change_pass', :id => @user 
  6. end

后來隨手改了下第5行,把redirect_to改為render,居然就OK了。網(wǎng)上找了下才發(fā)現(xiàn)redirect_to和render還是有很多區(qū)別的,我以前居然一點都沒有注意,汗..
redirect_to實現(xiàn)的是action方法的跳轉(zhuǎn),向瀏覽器發(fā)起一個新的請求,Ruby rails頁面跳轉(zhuǎn)具體使用方法如下:

代碼如下:

  1. redirect_to :action => 
    'edit', :id => 7 
  2. redirect_to "http:
    //wiisola.javaeye.com/" 
  3. redirect_to "/images/1.jpg" 
  4. redirect_to :back 

其中第4行是回到上一次訪問的頁面。
render可以翻譯成"渲染",也就是說,render僅僅渲染了一個新的模板,而沒有執(zhí)行相應(yīng)的action。render的用法如下:

 Ruby rails頁面跳轉(zhuǎn)代碼如下:

 
 
 
  1. render(:text => string) 
  2. render(:inline => string, 
    [:type => "rhtml"|"rxml"]) 
  3. render(:action => action_name) 
  4. render(:file => path, 
    [:use_full_path => true|false]) 
  5. render(:template => name) 
  6. render(:partial => name) 
  7. render(:nothing=>true) 
  8. render()

第1行:直接渲染出文本
第2行:把傳入的string渲染成模板(rhtml或者rxml)
第3行:直接調(diào)用某個action的模板,相當于forward到一個view
第4行:使用某個模板文件render, 當use_full_path參數(shù)為true時可以傳入相對路徑
第5行:使用模板名render,e.x.: render(:template => "blog/short_list")
第6行:以局部模板渲染
第7行:什么也不輸出,包括layout
第8行:默認的的render, 相當于render(:action => self)
補上一個手動render的例子: 
 
Ruby rails頁面跳轉(zhuǎn) 代碼如下:

 
 
 
  1. def search 
  2. @results =Search.
    find(params[:query]) 
  3. case @results 
  4. when 0 then render 
    :action=> "no_results" 
  5. when 1 then render 
    :action=> "show" 
  6. when 2..10 then render 
    :action=> "show_many" 
  7. end 
  8. end 
  9. def search 
  10. @results =Search.find
    (params[:query]) 
  11. case @results 
  12. when 0 then render 
    :action=> "no_results" 
  13. when 1 then render 
    :action=> "show" 
  14. when 2..10 then render 
    :action=> "show_many" 
  15. end 
  16. end 

但是我自己的問題仍然沒有解決,為什么用render渲染一個模板能夠顯示錯誤信息,但用redirect_to重新請求就沒有呢?也許看源碼能夠解決吧,可惜看不懂,汗..總之以后記住render和redirect_to的用法就是了。

以上就是我們?yōu)榇蠹医榻B的Ruby rails頁面跳轉(zhuǎn)的一些實現(xiàn)方法。


分享名稱:Rubyrails頁面跳轉(zhuǎn)知識一點通
本文路徑:http://uogjgqi.cn/article/dhopohh.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流