Posted by Captain Zhan
Wed, 01 Nov 2006 11:38:00 GMT
本节创建商店的用户管理系统. 创建存放用户资料的数据表,加入添加,删除用户功能, 后台管理用户权限审查功能,和用户登录 退出功能.
创建用户model: depot> ruby script/generate model user
修改depot/db/migrate/007_create_users.rb文件内容如下:
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.column :name, :string
t.column :hashed_password, :string
t.column :salt, :string #生成密码hash用的salt
end
end
Read more...
Posted in Ruby on Rails | no comments
Posted by Captain Zhan
Wed, 01 Nov 2006 11:34:00 GMT
上一节:Ruby on Rails实战--创建一个网上商店C小试Ajax
本节完成收银台功能. 为页面新增一个结账按钮,用户挑选商品后点击结账按钮时出现一个用户资料表单,用户填交后,系统将商品信息和用户信息保存到数据库中.
创建order model
depot> ruby script/generate model order
修改depot/db/migrate/005_create_orders.rb 内容为:
class CreateOrders < ActiveRecord::Migration
def self.up
create_table :orders do |t|
t.column :name, :string
t.column :address, :text
t.column :email, :string
t.column :pay_type, :string, :limit => 10
end
end
Read more...
Posted in Ruby on Rails | no comments
Posted by Captain Zhan
Tue, 31 Oct 2006 10:42:00 GMT
上一节:Ruby on Rails实战--创建一个网上商店B前台
本节将向商店加入一个Ajax购物篮,使商店产品列表在不刷新的情况下更新显示购物篮信息
修改depot/app/controllers/store_controller.rb文件,如下:
def index
@products = Product.find_products_for_sale
@cart = find_cart #加入对@cart的定义
end
def add_to_cart
begin
@product = Product.find(params[:id])
rescue
logger.error("Attempt to access invalid product #{params[:id]}")
redirect_to_index("Invalid product")
else
Read more...
Posted in Ruby on Rails | no comments
Posted by Captain Zhan
Mon, 30 Oct 2006 17:12:00 GMT
1.首先,我是一个新喜欢上越剧的人.我分不清越剧的派别, 但我打心底觉得越剧很美, 我希望它能重新流行起来.
2.我觉得问题的重点是怎样让越剧更好听, 让更多的人欢迎. 这是最终的目标. 学越剧的最终目标不是学的最像谁, 而是怎样才能受观众的喜爱.不能本未倒置.
3.观众是指大众,特别是现在不喜欢越剧的年青人, 而不是现在已经存在的少数越剧迷. 已经存在的越剧迷本来就不多, 而且他们越来越少. 新学越剧的人不应该只为这些人学越剧, 而应该面向大众. 如果这些老越剧迷(应该大多是老的吧)说你学的不像谁或谁, 1.对他们不要怜悯,因为他们还有大把老唱片 2.于自己,不用太在意他们的评价, 因为
Read more...
Posted in 越剧柔情 | no comments
Posted by Captain Zhan
Mon, 30 Oct 2006 12:47:00 GMT
1.Ruby是一个面向对象的(object-oriented)的编程语言.
Ruby中所有的操作元都是对象(object).
类(Class),方法(method),实例(instance),对象(object, class instance), constructor, instance variable, instance method, --当自然语言学家遇上程序语言...
method实例:
"dave".length
line_item_one.quantity
-1942.abs
cart.add_line_item(next_purchase)
2.命名
Read more...
Posted in Ruby on Rails | no comments
Posted by Captain Zhan
Mon, 30 Oct 2006 08:11:00 GMT
Ruby是一种面向对象(object-oriented)的计算机编程语言.由日本人松本行弘(Yukihiro "Matz" Matsumoto)于1993年发明.

Ruby之父 松本行弘(Matsumoto Yukihiro)
Read more...
Posted in Ruby on Rails | no comments
Posted by Captain Zhan
Fri, 27 Oct 2006 17:19:00 GMT
一山一峰不同岭
一花一草各有心
原天常生好心人
愿人常做好事情

Read more...
Posted in 越剧柔情 | no comments
Posted by Captain Zhan
Fri, 27 Oct 2006 13:01:00 GMT
上一节: Ruby on Rails实战--创建一个网上商店a
本节创建商店的前台模块, 也就是客户看到的页面.
1.创建前台Controller Store:depot> ruby script/generate controller store index
最后的index创建一个index Action,用作默认action
2.创建一个session,用来保存购物篮数据
depot> rake db:sessions:create
然后
depot> rake db:migrate
(users of Rails applications must have cookies enabled in their browsers.???)
在config/environment.rb中将
config.action_controller.session_store = :active_record_store
语句前的注解符#去除,启动数据库保存session功能
*使用depot> rake db:sessions:clear可以清空当前session内容
Read more...
Posted in Ruby on Rails | 1 comment
Posted by Captain Zhan
Thu, 26 Oct 2006 13:54:00 GMT
这是一个使用Ruby on Rails创建一个网上商店的实例. 实例来自<Agile Web Development with Rails>第二版 beta. 下面是我整理的笔记. 笔记对实例进行了注解, 记录我的学习路程, 同在学习Ruby on Rails的朋友可作为参考. 如果里面有什么错误,还请留言指正.
按学习日程,我把这个实例分为几段, 分别完成: 网上商店基本构架 Ruby语言入门
这是第一部分, 完成商店的基本构架.
首先要在准备好实例的学习环境, 参考: 在Windows平台上学习Ruby on Rails 的环境准备
1.it’s easier to throw something away if you didn’t spend a long time creating it.
2.使用笔+纸打草图以加快速度.
Read more...
Posted in Ruby on Rails | 1 comment
Posted by Captain Zhan
Thu, 26 Oct 2006 09:02:00 GMT
写之前要安装好环境, 如果是windows请参看:
在Windows平台上学习Ruby on Rails 的环境准备
linux参看:
在ubuntu6.06上安装apache2.2X + mysql + PHP + Ruby on Rails + Mongrel Cluster
mac参看:
从Ubuntu转到Mac OS X
所有命令行在Ruby Console Window里输入.
1.创建一个程序:work> rails demo
2.启动内建的WEBrick服务器:demo> ruby script/server
WEBrick是用来调测ROR程序的理想Web服务器. 这个服务器定时刷新访问服务器文件内容,方便调试.
如WEBrick非默认服务器,使用demo>ruby script/server webrick可以强制启动这个服务器.
启动后可用http://localhost:3000地址访问.
3.URL解释:
http://localhost:3000/demo/say/hello
相应功能如下:
http://域名/程序/Controller/Action
Read more...
Posted in Ruby on Rails | 19 comments