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

Ruby on Rails創(chuàng)建購(gòu)物頁(yè)面技巧一點(diǎn)通

開(kāi)發(fā) 開(kāi)發(fā)工具
Ruby on Rails創(chuàng)建購(gòu)物頁(yè)面是網(wǎng)頁(yè)開(kāi)發(fā)人員在實(shí)際操作中經(jīng)常會(huì)遇到的問(wèn)題。那么如何才能正確的實(shí)現(xiàn)這一功能需求呢?

Ruby on Rails是一款性能不錯(cuò)的WEB開(kāi)發(fā)框架。許多編程人員都靠這個(gè)開(kāi)發(fā)框架來(lái)實(shí)現(xiàn)簡(jiǎn)約編程。在這里我們將會(huì)為大家詳細(xì)介紹有關(guān)Ruby on Rails創(chuàng)建購(gòu)物頁(yè)面的一些技巧。#t#

 

這次我們使用上面維護(hù)的Products列表來(lái)創(chuàng)建一個(gè)最終用戶使用的購(gòu)物頁(yè)面。

1.創(chuàng)建控制器(Controller),命名為store,我們通過(guò)命令行來(lái)創(chuàng)建它:

depot> ruby script/generate controller Store index

打開(kāi)...rails_appsdepotappcontrollers目錄下的store_controller.rb文件,向其中添加Ruby on Rails創(chuàng)建購(gòu)物頁(yè)面的代碼:

 

  1. def index  
  2. @products = 
    Product.salable_items  
  3. end 

當(dāng)然,我們還需要給Product定義salable_items方法,打開(kāi)rails_appsdepotappmodels目錄下的product.rb文件,添加代碼:

 

  1. def self.salable_items  
  2. find(:all,  
  3. :conditions => 
    "date_available 
    < = now()",  
  4. :order => "date_available desc")  
  5. end 

2.創(chuàng)建表示層,在rails_appsdepotappviewsstore目錄下,創(chuàng)建一個(gè)index.rhtml文件,修改其內(nèi)容如下:

 

  1. < html> 
  2. < head> 
  3. < title>Pragprog Books Online Store
    < /title> 
  4. < %= stylesheet_link_tag "depot",
     
    :media => "all" %> 
  5. < /head> 
  6. < body> 
  7. < div id="banner"> 
  8. < img src="http://images.
    cnblogs.com/logo.png"
    /> ||  
  9. < %= @page_title || "Pragmatic 
    Bookshelf" %
    > 
  10. < /div> 
  11. < div id="columns"> 
  12. < div id="side"> 
  13. < a href="http://www....">Home
    < /a>< br /> 
  14. < a href="http://www..../faq">
    Questions< /a>< br /> 
  15. < a href="http://www..../news">
    News< /a>< br /> 
  16. < a href="http://www..../contact">
    Contact< /a>< br /> 
  17. < /div> 
  18. < div id="main"> 
  19. < %= @content_for_layout %> 
  20. < % for product in @products -%> 
  21. < div class="catalogentry"> 
  22. < img src="< %= product.image_url %>"/> 
  23. < h3>< %= h(product.title) %>< /h3> 
  24. < %= product.description %> 
  25. < span class="catalogprice">< %= 
    sprintf("$%0.2f", product.price) %
    >< /span> 
  26. < %= link_to 'Add to Cart',  
  27. {:action => 'add_to_cart', :id => product },  
  28. :class => 'addtocart' %>< br/> 
  29. < /div> 
  30. < div class="separator">&nbsp;< /div> 
  31. < % end %> 
  32. < %= link_to "Show my cart", 
    :action => "display_cart" %> 
  33. < /div> 
  34. < /div> 
  35. < /body> 
  36. < /html> 

可以看到,在index.rhtml中,使用了css樣式,css樣式的文件名字叫depot

< %= stylesheet_link_tag "depot", :media => "all" %>

我們可以在rails_appsdepotpublicstylesheets目錄下創(chuàng)建一個(gè)depot.css文件來(lái)定義我們的樣式以完成Ruby on Rails創(chuàng)建購(gòu)物頁(yè)面的操作。

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

2009-12-15 10:31:30

Ruby rails頁(yè)

2009-12-15 14:27:30

Ruby存取器

2009-12-14 15:30:43

安裝Ruby on R

2009-12-17 17:37:42

Ruby on Rai

2010-01-04 19:22:49

Silverlight

2009-12-18 14:19:45

Ruby on Rai

2009-07-20 09:12:54

Ruby on Rai

2009-12-18 13:13:59

Ruby on Rai

2009-12-16 17:24:26

Ruby on Rai

2009-12-16 17:07:27

Ruby on Rai

2009-12-16 15:46:41

Ruby on rai

2009-12-17 14:36:57

Ruby on Rai

2009-08-27 10:21:22

Ruby on Rai

2012-07-27 09:36:33

金山WPSWPS移動(dòng)版

2009-11-03 09:09:19

VB.NET類(lèi)

2009-12-31 13:45:13

Silverlight

2009-11-09 13:56:15

WCF Stream對(duì)

2009-12-24 17:10:42

WPF動(dòng)畫(huà)類(lèi)

2009-10-22 09:29:23

CLR是什么

2009-12-16 17:31:30

Ruby on Rai
點(diǎn)贊
收藏

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