成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Ruby on Rails列表頁(yè)面如何進(jìn)行優(yōu)化

開發(fā) 開發(fā)工具
Ruby on Rails列表頁(yè)面在實(shí)際編程中是非常常見的。對(duì)于初學(xué)者來說,對(duì)于列表的優(yōu)化是一個(gè)比較重要的知識(shí)點(diǎn)。希望大家可以通過本文介紹的內(nèi)容充分掌握這一技巧。

Ruby on Rails列表頁(yè)面可以被我們進(jìn)行優(yōu)化。美化后的列表頁(yè)面可以幫助我們一目了然的讀懂列表,方便我們編寫程序。在這里我們將會(huì)介紹Ruby on Rails列表頁(yè)面的一些美化技巧。#t#

1.  打開appviewsadminlist.rhtml文件,可以看到下面的代碼

 

  1. < h1>Listing products< /h1> 
  2. < table> 
  3. < tr> 
  4. <% for column in Product.content_columns %> 
  5. < th>< %= column.human_name %>< /th> 
  6. <% end %> 
  7. < /tr> 
  8. <% for product in @products %> 
  9. < tr> 
  10. <% for column in Product.content_columns %> 
  11. <td><%=h product.send(column.name) %></td> 
  12. <% end %> 
  13. <td><%= link_to 'Show', :action => 'show',
     
    :id => product %></td> 
  14. <td><%= link_to 'Edit', :action => 'edit', 
    :id => product %></td> 
  15. <td><%= link_to 'Destroy', { :action => 
    'destroy', 
    :id => product }, :confirm => 
    'Are you sure?', 
    :method => :post %></td> 
  16. </tr> 
  17. <% end %> 
  18. </table> 
  19. <%= link_to 'Previous page', { :page =>
     @product_pages.current.previous } if 
    @product_pages.current.previous %
    > 
  20. <%= link_to 'Next page', { :page => 
    @product_pages.current.next } if 
    @product_pages.current.next %
    > 
  21. <br /> 
  22. <%= link_to 'New product', :action => 'new' %> 

 

可以看到,list頁(yè)面實(shí)際上是對(duì)Products做循環(huán),然后對(duì)每行,每列逐個(gè)輸出到一個(gè)Table中,而link_to函數(shù),我們?cè)谇懊娴膬?nèi)容中也使用過。

Ruby on Rails列表頁(yè)面2.修改appviewsadminlist.rhtml的內(nèi)容,如下:

 

  1. <h1>Product Listing</h1> 
  2. <table cellpadding="5" cellspacing="0"> 
  3. <%  
  4. odd_or_even = 0 
  5. for product in @products  
  6. odd_or_even = 1 - odd_or_even  
  7. %> 
  8. <tr valign="top" class="
    ListLine<%= odd_or_even %>"
    > 
  9. <td> 
  10. <img width="60" height="70" src="
    <%= product.image_url %>"
    /> 
  11. </td> 
  12. <td width="60%"> 
  13. <span class="ListTitle"><%=
     h(product.title) %
    ></span><br /> 
  14. <%= h(truncate(product.description, 80)) %> 
  15. </td> 
  16. <td align="right"> 
  17. <%= product.date_available.strftime
    ("%y-%m-%d") %
    ><br/> 
  18. <strong>$<%= sprintf("%0.2f", 
    product.price) %
    ></strong> 
  19. </td> 
  20. <td class="ListActions"> 
  21. <%= link_to 'Show', :action => 'show', 
    :id => product %><br/> 
  22. <%= link_to 'Edit', :action => 'edit', 
    :id => product %><br/> 
  23. <%= link_to 'Destroy', { :action => 
    'destroy', 
    :id => product },  
  24. :confirm => "Are you sure?" %> 
  25. </td> 
  26. </tr> 
  27. <% end %> 
  28. </table> 
  29. <%= if @product_pages.current.previous  
  30. link_to("Previous page", { :page => 
    @product_pages.current.previous })  
  31. end  
  32. %> 
  33. <%= if @product_pages.current.next  
  34. link_to("Next page", { :page =>
     @product_pages.current.next })  
  35. end  
  36. %> 
  37. <br /> 
  38. <%= link_to 'New product', :action => 'new' %> 

 


Ruby on Rails列表頁(yè)面3.在上面的代碼里,我們可以看到td class="ListActions"這樣的代碼,下來我們添加這些css樣式的內(nèi)容:

將下面的內(nèi)容添加到publicstylesheets scaffold.css文件中:

 

  1. .ListTitle {  
  2. color: #244;  
  3. font-weight: bold;  
  4. font-size: larger;  
  5. }  
  6. .ListActions {  
  7. font-size: x-small;  
  8. text-align: right;  
  9. padding-left: 1em;  
  10. }  
  11. .ListLine0 {  
  12. background: #e0f8f8;  
  13. }  
  14. .ListLine1 {  
  15. background: #f8b0f8;  

OK,今天Ruby on Rails列表頁(yè)面的優(yōu)化內(nèi)容就介紹到這里。

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

2010-07-12 09:22:05

RubyRuby on rai

2009-12-16 15:23:33

Ruby on rai

2009-12-16 17:24:26

Ruby on Rai

2015-10-14 17:27:18

性能

2015-10-10 11:00:05

RubyRails性能

2017-07-28 11:31:59

iOS結(jié)構(gòu)優(yōu)化項(xiàng)目

2010-03-15 15:11:50

Python列表

2009-08-27 10:21:22

Ruby on Rai

2009-12-15 10:31:30

Ruby rails頁(yè)

2009-12-14 15:37:35

Ruby on Rai

2009-08-06 09:13:36

Ruby on Rai

2009-12-17 09:14:14

Ruby on Rai

2011-07-06 08:46:30

2009-12-16 17:00:43

Ruby on Rai

2009-12-16 16:37:59

Ruby on Rai

2020-02-12 08:50:05

Linux命令啟動(dòng)時(shí)間

2009-12-14 15:30:43

安裝Ruby on R

2009-12-17 14:29:50

Ruby on Rai

2023-12-01 10:19:00

接口優(yōu)化事務(wù)

2010-07-16 14:30:25

Perl數(shù)組
點(diǎn)贊
收藏

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

主站蜘蛛池模板: 成人免费黄色片 | 免费国产视频 | 国产精品久久久久久久久久久久久 | 在线视频成人 | 日韩精品无码一区二区三区 | 精品99在线 | 亚洲先锋影音 | 狠狠亚洲| 91九色视频 | 午夜精品一区二区三区在线视 | 天堂色综合 | 国产乱人伦精品一区二区 | 国产成人精品久久二区二区 | 黄视频免费观看 | 亚洲成人免费网址 | 91视频免费黄 | 中文字幕亚洲区 | 国产二区视频 | 精品国产18久久久久久二百 | 国产欧美日韩久久久 | 乱一性一乱一交一视频a∨ 色爱av | 精品视频在线观看 | 午夜影院官网 | 成人在线观看免费 | 日中文字幕在线 | 国产性色视频 | 天天夜天天操 | 欧美精品久久久久久久久久 | 国产精品射 | 免费a网 | 欧美色综合一区二区三区 | 亚洲一区二区精品视频 | 精品中文字幕在线观看 | 国产一区二区黑人欧美xxxx | 欧美黄a| 男女搞网站 | 亚洲一区二区视频 | 亚洲精品成人av | 亚洲国产精品一区 | 国产精品免费一区二区三区四区 | 午夜爽爽男女免费观看hd |