`
waveeee
  • 浏览: 52515 次
  • 来自: 上海
社区版块
存档分类
最新评论

agile rails depot 2

    博客分类:
  • ruby
阅读更多
appointment: this demo ran in ubuntu, and Rails 2.2.2
the demo comes from agile web development with rails 3
script>>some linux script
mysql>some db command

----------------------------------
Catalog Display
-seeing what the application looks like from the buyer's point view

----------------------------------
step 1
create the catalog listing
create a controller
script>>script/generate controller store index
and point the browser as http://localhost:3000/store

[if you see no route....  restart you server is ok]

and will add some thing for the store index
in controller: app/controllers/store_controller.rb
add index method to response the index request
 def index
    @products = Product.find_products_for_sale #1
  end

#1 add find_products_for_sale method in model Product
in app/models/product.rb
  def self.find_products_for_sale
    find(:all, :order => "title") 
  end

edit view: app/views/store/index.html.erb
<% for product in @products -%>
<div class="entry">
<%= image_tag(product.image_url) %>
<h3><%=h product.title %></h3>
<%= product.description %>
<div class="price-line">
<span class="price"><%= product.price %></span>
</div>
</div>
<% end %>


step2
add a page layout
views/layouts/store.html.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html>
<head>
<title>Pragprog Books Online Store</title>
<%= stylesheet_link_tag "depot" , :media => "all" %>
</head>
<body id="store">
<div id="banner">
<%= image_tag("logo.png" ) %>
<%= @page_title || "Pragmatic Bookshelf" %>
</div>
<div id="columns">
<div id="side">
<a href="http://www....">Home</a><br />
<a href="http://www..../faq">Questions</a><br />
<a href="http://www..../news">News</a><br />
<a href="http://www..../contact">Contact</a><br />
</div>
<div id="main">
<%= yield :layout %>
</div>
</div>
</body>
</html>



step3
format the price with the help method
edit view: app/views/store/index.html.erb
<span class="price" ><%= number_to_currency(product.price) %></span>


step4
add to cart
edit view: app/views/store/index.html.erb
<%= button_to "Add to Cart" %>
  • 大小: 151.2 KB
分享到:
评论

相关推荐

    Agile+Web+Development+with+Rails中文版.pdf

    《Agile Web Development with Rails》是一本经典的Rails开发指南,中文版的出版使得更多的中国开发者能够深入理解并应用敏捷开发方法与Ruby on Rails框架。这本书是Rails开发者的必备参考资料,它详细介绍了如何...

    Agile Web Development with Rails 4

    Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of ...

    Agile Web Development with Rails

    《Agile Web Development with Rails》(敏捷Web开发:Ruby on Rails)这本书,作为Rails开发新手的教材,强调了敏捷开发方法,并以其帮助开发者建立起一个实用的Web应用。从给出的文件信息来看,这本书正在编写过程...

    Agile Web Development with Rails (PDF)

    #### 2. 模型-视图-控制器(MVC)架构 Rails遵循MVC架构模式,将应用程序分为三个核心部分:模型(Model)、视图(View)和控制器(Controller)。模型负责数据管理和业务逻辑;视图用于展示数据,与用户交互;控制...

    Agile Web Development With Ruby On Rails第一及第二版

    《Agile Web Development With Ruby On Rails》是两本广受欢迎的书籍,主要涵盖了使用Ruby on Rails框架进行敏捷Web开发的知识。这本书的第1版和第2版分别详细讲解了如何运用敏捷开发方法来构建高效、可扩展且易于...

    agile-web-development-with-rails_2

    - **社区贡献:** Rails 2更加注重社区的反馈和贡献,这使得框架能够更快地响应用户需求并修复问题。 #### 五、实战案例分析 本书通过实际案例讲解了如何使用Rails构建Web应用,包括但不限于: - **用户认证系统:...

    Agile Web Development with Rails 3nd Edition Beta.pdf

    本书《敏捷Web开发与Rails》第三版是基于Rails 2编写的。截至本书印刷时,当前可用的Rails Gem版本为2.1。书中所包含的所有代码均已在该版本上进行了测试。 在本书撰写初期,其内容与第二版相同,后者涵盖了Rails ...

    Agile Web Development with Rails, 2nd Edition

    Justin Gehtland , Andreas Schwarz &lt;br&gt; &lt;br&gt;http://ecx.images-amazon.com/images/I/51YZKK7C2WL._SS500_.jpg&lt;br&gt;&lt;br&gt;&lt;br&gt;http://www.amazon.com/Agile-Web-Development-Rails-2nd/dp/0977616630

    Agile Web Development with Rails,Fourth Edition 第四版

    《敏捷Web开发与Rails》第四版是一本专为软件开发者设计的权威指南,全面涵盖了使用Ruby on Rails框架进行敏捷Web应用开发的知识。Rails 3是该版本的重点,它引入了许多新特性和改进,使得开发过程更为高效且灵活。...

    Agile Web Development with Rails 4th edition(敏捷Web开发与Rails:程序指南 第四版)

    2. **ActionController**: 在这一版中,ActionController也有所改进,增加了更多的过滤器和助手方法,使得控制器更易于管理和测试。同时,对于JSON和XML响应的支持也得到了增强,为API开发提供了便利。 3. **...

    Agile Web Development with Rails 2nd Edition源码

    2. **Ruby on Rails**: Rails是基于Ruby语言的开源Web应用框架,遵循MVC(模型-视图-控制器)架构模式。它提倡DRY(Don't Repeat Yourself)原则,简化了Web开发过程。书中源码展示了Rails如何通过DSL(领域特定语言...

    Agile Web Development with Rails for Rails 3.2

    ### Agile Web Development with Rails for Rails 3.2 #### 核心知识点概览 - **Rails 3.2概述** - **敏捷开发方法论** - **Model-View-Controller (MVC) 模式** - **Ruby on Rails基础与高级特性** - **面向对象...

    agile web development with rails 5(英文电子书)

    agile web development with rails 5(英文电子书).............................................................................................................................................................

    Agile Web Development with Rails 1-14节_ppt(老师发的修正版)

    Agile Web Development with Rails 1-14节_ppt(老师发的修正版)

    agile web development with rails2代码

    《敏捷Web开发与Rails2》是一本专注于使用Ruby on Rails框架进行高效Web应用开发的书籍。Rails是基于Ruby语言的开源框架,它以其简洁、高效的特性在开发社区中备受推崇。该压缩包文件包含了该书的源代码示例,帮助...

Global site tag (gtag.js) - Google Analytics