自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Ruby on Rails頁(yè)面跳轉(zhuǎn)實(shí)現(xiàn)方法總結(jié)

開發(fā) 開發(fā)工具
Ruby on Rails頁(yè)面跳轉(zhuǎn)的實(shí)現(xiàn)對(duì)于以俄國(guó)有相當(dāng)豐富經(jīng)驗(yàn)的編程人員來(lái)說(shuō)是一個(gè)比較簡(jiǎn)單的方法。希望通過本文介紹的內(nèi)容大家可以充分掌握這一技巧的應(yīng)用。

Ruby on Rails頁(yè)面跳轉(zhuǎn)的實(shí)現(xiàn),在實(shí)際使用中是經(jīng)常遇到的一個(gè)問題。在這里,我們會(huì)為大家詳細(xì)介紹Ruby on Rails頁(yè)面跳轉(zhuǎn)的一些實(shí)現(xiàn)技巧。#t#

Ruby on Rails頁(yè)面跳轉(zhuǎn)1.將appcontrollers目錄下的say_controller.rb文件的內(nèi)容改成下面這樣:

 

  1. class SayController 
    < ApplicationController 
  2. def Hello  
  3. @time = Time.now  
  4. end  
  5. def goodby  
  6. end  
  7. end 

 

我們***添加了:

def goodby
end

Ruby on Rails頁(yè)面跳轉(zhuǎn)2.修改appviewssay目錄下的hello.rhtml的內(nèi)容:

 

  1. <html> 
  2. <p> 
  3. Say <a href="
    /say/goodbye"
    >GoodBye</a>!  
  4. </p> 
  5. </html> 

 

Ruby on Rails頁(yè)面跳轉(zhuǎn)3.下面我們要在appviewssay目錄下創(chuàng)建一個(gè)goodbye.rhtml文件,內(nèi)容如下:

 

  1. <html> 
  2. <head> 
  3. <title>See You Later!</title> 
  4. </head> 
  5. <body> 
  6. <h1>Goodbye!</h1> 
  7. <p> 
  8. It was nice having you here.  
  9. </p> 
  10. </body> 
  11. </html> 

 

Ruby on Rails頁(yè)面跳轉(zhuǎn)4.在瀏覽器地址欄中輸入:http://127.0.0.1:3000/say/hello,再試試點(diǎn)鏈接看看,頁(yè)面已經(jīng)可以遷移了。

Ruby on Rails頁(yè)面跳轉(zhuǎn)5.現(xiàn)在我們?cè)偬砑佑蒰oodbye頁(yè)面到hello頁(yè)面的鏈接,修改goodbye.rhtml的內(nèi)容為:

 

  1. <html> 
  2. <p> 
  3. Say <a href="
    /say/hello"
    >Hello</a>!  
  4. </p> 
  5. </html> 

 

再試試看,兩個(gè)頁(yè)面已經(jīng)可以互相跳轉(zhuǎn)了。

Ruby on Rails頁(yè)面跳轉(zhuǎn)6.在上面的代碼中,我們看到頁(yè)面間的遷移使用的是路徑來(lái)定位,如果頁(yè)面存放的位置發(fā)生了變化,那么跳轉(zhuǎn)肯定會(huì)失敗,更安全的是使用下面的方式。

修改hello.rhtml的內(nèi)容:

 

  1. <html> 
  2. <head> 
  3. <title>Hello, Rails!</title> 
  4. </head> 
  5. <body> 
  6. <h1>Hello from Rails!</h1> 
  7. <p> 
  8. It is now <%= @time %>.  
  9. </p> 
  10. <p> 
  11. Time to say  
  12. <%= link_to "GoodBye!",
     
    :action => "goodbye" %> 
  13. </p> 
  14. </body> 
  15. </html> 

 

修改goodbye.rhtml的內(nèi)容:

 

  1. <html> 
  2. <head> 
  3. <title>See You Later!</title> 
  4. </head> 
  5. <body> 
  6. <h1>Goodbye!</h1> 
  7. <p> 
  8. It was nice having you here.  
  9. </p> 
  10. <p> 
  11. Say <%= link_to "Hello", 
    :action=>"hello" %> again.  
  12. </p> 
  13. </body> 
  14. </html> 

 

注意代碼里的兩句:

 

  1. <%= link_to "GoodBye!", 
    :action => "goodbye" %> 
  2. <%= link_to "Hello", 
    :action=>"hello" %> 

 

可以看到,實(shí)際上就是調(diào)用了goodbye和hello兩個(gè)action。

OK,Ruby on Rails頁(yè)面跳轉(zhuǎn)就介紹到這里,先求快速挺進(jìn),概念的東西先不追究,希望我能堅(jiān)持下去。

責(zé)任編輯:曹凱 來(lái)源: 新客網(wǎng)
相關(guān)推薦

2009-12-15 10:31:30

Ruby rails頁(yè)

2009-12-17 14:29:50

Ruby on Rai

2009-08-27 10:21:22

Ruby on Rai

2009-12-17 11:14:50

Ruby on Rai

2009-12-24 17:57:53

WPF頁(yè)面跳轉(zhuǎn)

2009-12-16 17:50:58

Ruby on Rai

2015-05-05 10:51:32

php頁(yè)面跳轉(zhuǎn)方法

2009-07-23 13:35:33

Ruby on Rai

2009-08-06 09:13:36

Ruby on Rai

2009-12-16 15:46:41

Ruby on rai

2009-12-17 14:36:57

Ruby on Rai

2009-12-17 09:14:14

Ruby on Rai

2009-12-17 15:02:32

Ruby on Rai

2009-12-17 11:27:31

Ruby時(shí)間方法

2015-10-10 11:00:05

RubyRails性能

2009-12-16 16:37:59

Ruby on Rai

2021-05-18 09:49:08

鴻蒙HarmonyOS應(yīng)用

2015-10-14 17:27:18

性能

2009-12-14 15:30:43

安裝Ruby on R

2009-07-03 17:24:31

Servlet頁(yè)面跳轉(zhuǎn)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)