This episode starts off with a big, messy template. Watch as this code shrinks and becomes more readable while the interface stays the same.
<!-- views/carts/show.rhtml -->
<% title "Shopping Cart" %>
<table id="line_items">
<tr>
<th>Product</th>
<th>Qty</th>
<th class="price">Unit Price</th>
<th class="price">Full Price</th>
</tr>
<%= render :partial => 'line_item', :collection => @cart.line_items %>
<tr>
<td class="total price" colspan="4">
Total: <%= number_to_currency @cart.total_price %>
</td>
</tr>
</table>
<!-- views/carts/_line_item.rhtml -->
<tr class="<%= cycle :odd, :even %>">
<td><%=h line_item.product.name %></td>
<td class="qty"><%= line_item.quantity %></td>
<td class="price"><%= free_when_zero(line_item.unit_price) %></td>
<td class="price"><%= free_when_zero(line_item.full_price) %></td>
</tr>
# models/line_item.rb
def full_price
unit_price*quantity
end
# models/cart.rb
def total_price
line_items.to_a.sum(&:full_price)
end
# helpers/carts_helper.rb
def free_when_zero(price)
price.zero? ? "FREE" : number_to_currency(price)
end
分享到:
相关推荐
"The steps to cleaning up a system.zip" 文件很可能包含了一套详细的操作指南,帮助用户有效地清理他们的系统。下面将详细介绍这个过程,并提供一些关键知识点。 1. **检查并删除临时文件**:系统在运行过程中会...
这是因为系统镜像文件未完全加载成功,且开始执行"Starting Cleaning Up and Shutting Down Daemons."守护程序时,出现网络不稳定现象,则导致守护程序执行失败打印,以及系统 halt。 四、解决方案 为了解决该问题...
Enables the reader to design data cleaning processes for either one-off analytical purposes or for setting up production systems that clean data on a regular basis. Explores statistical techniques for...
昆腾磁带库(ScalarI40/I80)设置清洁槽和导入清洁磁带的步骤涉及几个关键的技术知识点,具体包括Web用户界面(WebGUI)操作、磁带库分区设置、清洁槽配置、清洁磁带的导入以及锁定/解锁I/E(输入/输出)站的流程。...
The book is structured to offer practical solutions to common issues encountered during the data cleaning process. It covers character and numeric variable checks, handling missing values, working ...
- **实践应用**:例如,在书中的“Description of the Raw Data File PATIENTS.TXT”部分,通过使用 `PROC FREQ` 来统计不同病人的特征(如性别、年龄等),可以帮助用户快速发现数据中的问题,比如某个分类变量中...
《win7-usb-3.0制作工具:高效便捷的系统安装新途径》 在数字化时代,电脑系统安装不再局限于传统的光盘,U盘作为便携式的存储设备,逐渐成为系统安装的主流方式。"win7-usb-3.0制作工具"就是这样一款专为制作U盘...
《Visual Studio 2017 2019 2022本地包缓存清理工具详解》 在软件开发领域,Visual Studio作为一款强大的集成开发环境(IDE),深受程序员们的喜爱。然而,在频繁的使用过程中,Visual Studio会积累大量的本地包...
MAGIX Video Sound Cleaning Lab.part3MAGIX Video Sound Cleaning Lab.part3MAGIX Video Sound Cleaning Lab.part3
- **__stdcall**: Used for most Win32 API functions, where parameters are passed right-to-left onto the stack, and the callee is responsible for cleaning up the stack. - **__cdecl**: Typically used for...
This is codes for quiz for "getting and cleaning data" in coursera.
MAGIX Video Sound Cleaning Lab.part1MAGIX Video Sound Cleaning Lab.part1MAGIX Video Sound Cleaning Lab.part1
MAGIX Video Sound Cleaning Lab.part2MAGIX Video Sound Cleaning Lab.part2MAGIX Video Sound Cleaning Lab.part2
This is notes for "getting and cleaning data" using swirl package
# Cleaning the datapython facebook.pypython whatsapp.py# Combining both the data sets into onepython comb.py# To get the plotspython save_plots.py 您将在Plots目录中将所有图另存为jpeg。
Terms of reference for the purchase of automated equipment for chemical cleaning of semiconductor wafers.docx
Chu X, Ilyas IF, Krishnan S, Wang J. Data cleaning: Overview and emerging challenges. InProceedings of the 2016 International Conference on Management of Data 2016 Jun 26 (pp. 2201-2206). ACM.
1. **Modern View (since the 1990s)**: Acting rationally, focusing on the development of intelligent agents that make rational decisions. 2. **Acting Humanly**: Inspired by Turing’s question "Can ...