Agile Web Development with Rails 读书笔记 (三)
2007-03-15 11:05
405 查看
从第7章开始逐步有了点难度,很多地方由于语法不熟练,在调试的过程中出现了错误有几个点方要注意一下:
网页尽量使用CSS,多使用Div,以方便视图的定制和调整。
页面装饰中要注意添加<%= @content_for_layout %>做占位符号。
在调试Cookie中,要注意多清理Session,我在调试中由于之前放入Session中的内容是错误的,导致后边的显示不对,开始以为是程序逻辑的错误,后来清理了Cookie后,程序才正常。
新建立的模型和手工建立的类,要在ApplicationController中进行定义,格式如: model :cart。
如果在类中存在Private方法,要注意和Public方法的次序,以免造成,public方法变成private方法。
在函数中默认最后一条语句是该函数的返回值,例如:
def self.for_product(product)
item = self.new
item.quantity = 1
item.product = product
item.unit_price = product.price
item
end
我在弄的时候,就没有写最后一句item,结果就怎么都不对。
由于没有仔细的看Ruby语法相关的书,部分语法还是觉得稀奇古怪的,需要不断的熟悉看,例如下边的语法:
@items << LineItem.for_product(product)
最后要说的就是<% -%>的语法要注意,会取消输出中紧跟的换行。
网页尽量使用CSS,多使用Div,以方便视图的定制和调整。
页面装饰中要注意添加<%= @content_for_layout %>做占位符号。
在调试Cookie中,要注意多清理Session,我在调试中由于之前放入Session中的内容是错误的,导致后边的显示不对,开始以为是程序逻辑的错误,后来清理了Cookie后,程序才正常。
新建立的模型和手工建立的类,要在ApplicationController中进行定义,格式如: model :cart。
如果在类中存在Private方法,要注意和Public方法的次序,以免造成,public方法变成private方法。
在函数中默认最后一条语句是该函数的返回值,例如:
def self.for_product(product)
item = self.new
item.quantity = 1
item.product = product
item.unit_price = product.price
item
end
我在弄的时候,就没有写最后一句item,结果就怎么都不对。
由于没有仔细的看Ruby语法相关的书,部分语法还是觉得稀奇古怪的,需要不断的熟悉看,例如下边的语法:
@items << LineItem.for_product(product)
最后要说的就是<% -%>的语法要注意,会取消输出中紧跟的换行。
相关文章推荐
- Agile Web Development with Rails 读书笔记 (一)
- Agile Web Development with Rails 读书笔记 (二)
- Agile Web Development with Rails 读书笔记 (四)
- Agile Web Development with Rails第十一章笔记——任务F:Ajax初体验
- agile WEB development with rails的笔记
- Agile Web Development with Rails第六章笔记——任务A:创建应用程序
- Agile Web Development with Rails第十章笔记——任务E:更智能的购物车
- Agile Web Development with Rails第八章笔记——任务C:商品目录显示
- Agile Web Development with Rails第十二章笔记——任务G:付款
- Agile Web Development with Rails第九章笔记——任务D:创建购物车
- Agile Web Development with Rails第七章笔记——任务B:验证
- Agile Web Development with Rails 翻译(二)
- Agile Web Development with Rails 翻译(八)
- Agile Web Development with Rails 翻译(十五)
- 《Agile web Development With Rails (4th Edition·第四版)》翻译二
- Agile Web Development with Rails
- Agile Web Development with Rails 翻译(九)
- Agile Web Development with Rails 翻译(十六)
- 《Agile Web Development with Rails》读书笔记(四)
- Agile Web Development with Rails 翻译(三)