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

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

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

Ruby on Rails列表頁面可以被我們進行優(yōu)化。美化后的列表頁面可以幫助我們一目了然的讀懂列表,方便我們編寫程序。在這里我們將會介紹Ruby on Rails列表頁面的一些美化技巧。#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頁面實際上是對Products做循環(huán),然后對每行,每列逐個輸出到一個Table中,而link_to函數(shù),我們在前面的內(nèi)容中也使用過。

Ruby on Rails列表頁面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列表頁面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ōu)化內(nèi)容就介紹到這里。

責任編輯:曹凱 來源: 新客網(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性能

2010-03-15 15:11:50

Python列表

2017-07-28 11:31:59

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

2009-08-27 10:21:22

Ruby on Rai

2009-12-15 10:31:30

Ruby rails頁

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

2009-12-17 14:29:50

Ruby on Rai

2009-12-14 15:30:43

安裝Ruby on R

2020-02-12 08:50:05

Linux命令啟動時間

2023-12-01 10:19:00

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

2010-07-16 14:30:25

Perl數(shù)組
點贊
收藏

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