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

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供本溪網(wǎng)站建設(shè)、本溪做網(wǎng)站、本溪網(wǎng)站設(shè)計(jì)、本溪網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、本溪企業(yè)網(wǎng)站模板建站服務(wù),十載本溪做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
1. 打開appviewsadminlist.rhtml文件,可以看到下面的代碼
- <h1>Listing products</h1>
- <table>
- <tr>
- <% for column in Product.content_columns %>
- <th>< %= column.human_name %>< /th>
- <% end %>
- </tr>
- <% for product in @products %>
- <tr>
- <% for column in Product.content_columns %>
<%=h product.send(column.name) %> - <% end %>
<%= link_to 'Show', :action => 'show',
:id => product %><%= link_to 'Edit', :action => 'edit',
:id => product %><%= link_to 'Destroy', { :action =>
'destroy', :id => product }, :confirm =>
'Are you sure?', :method => :post %>- <% end %>
- <%= link_to 'Previous page', { :page =>
@product_pages.current.previous } if
@product_pages.current.previous %> - <%= link_to 'Next page', { :page =>
@product_pages.current.next } if
@product_pages.current.next %>
/>- <%= link_to 'New product', :action => 'new' %>
可以看到,list頁面實(shí)際上是對(duì)Products做循環(huán),然后對(duì)每行,每列逐個(gè)輸出到一個(gè)Table中,而link_to函數(shù),我們?cè)谇懊娴膬?nèi)容中也使用過。
Ruby on Rails列表頁面2.修改appviewsadminlist.rhtml的內(nèi)容,如下:
Product Listing
- <%
- odd_or_even = 0
- for product in @products
- odd_or_even = 1 - odd_or_even
- %>
ListLine<%= odd_or_even %>"> <%= product.image_url %>"/>
- <%=
h(product.title) %>- <%= h(truncate(product.description, 80)) %>
- <%= product.date_available.strftime
("%y-%m-%d") %>- $<%= sprintf("%0.2f",
product.price) %>- <%= link_to 'Show', :action => 'show',
:id => product %>- <%= link_to 'Edit', :action => 'edit',
:id => product %>- <%= link_to 'Destroy', { :action =>
'destroy', :id => product },- :confirm => "Are you sure?" %>
- <% end %>
- <%= if @product_pages.current.previous
- link_to("Previous page", { :page =>
@product_pages.current.previous })- end
- %>
- <%= if @product_pages.current.next
- link_to("Next page", { :page =>
@product_pages.current.next })- end
- %>
- <%= link_to 'New product', :action => 'new' %>
Ruby on Rails列表頁面3.在上面的代碼里,我們可以看到td class="ListActions"這樣的代碼,下來我們添加這些css樣式的內(nèi)容:
將下面的內(nèi)容添加到publicstylesheets scaffold.css文件中:
- .ListTitle {
- color: #244;
- font-weight: bold;
- font-size: larger;
- }
- .ListActions {
- font-size: x-small;
- text-align: right;
- padding-left: 1em;
- }
- .ListLine0 {
- background: #e0f8f8;
- }
- .ListLine1 {
- background: #f8b0f8;
- }
OK,今天Ruby on Rails列表頁面的優(yōu)化內(nèi)容就介紹到這里。
當(dāng)前題目:RubyonRails列表頁面如何進(jìn)行優(yōu)化
URL鏈接:http://m.fisionsoft.com.cn/article/cdhshsd.html


咨詢
建站咨詢
