Ruby on Rails实战--创建一个网上商店E用户管理模块

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  | no comments

Ruby on Rails实战--创建一个网上商店D收银台

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  | no comments

Ruby on Rails实战--创建一个网上商店C小试Ajax

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  | no comments

Ruby语言入门

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  | no comments

Ruby语言简介

Posted by Captain Zhan Mon, 30 Oct 2006 08:11:00 GMT


Ruby是一种面向对象(object-oriented)的计算机编程语言.由日本人松本行弘(Yukihiro "Matz" Matsumoto)于1993年发明.
Ruby语言简介
Ruby之父 松本行弘(Matsumoto Yukihiro)
Read more...

Posted in  | no comments

Ruby on Rails实战--创建一个网上商店B前台

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  | 1 comment

Ruby on Rails实战--创建一个网上商店a

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  | 1 comment

Ruby on Rails入门 --写第一个程序

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  | 19 comments

在Windows平台上学习Ruby on Rails 的环境准备

Posted by Captain Zhan Thu, 26 Oct 2006 09:00:00 GMT


1.到http://instantrails.rubyforge.org/wiki/wiki.pl下载InstantRails整合包. 包内带Apache,MySQL,Ruby和Rails. InstantRails解压缩即可使用,不用安装.
2.在InstantRails带的命令行平台(Rails Applications...=>Open Ruby Console Window)运行命令.
3.到http://www.radrails.org/下载RadRails在Windows平台的Ruby/Rails开发平台. 这个软件需要JRE支持.
4.桌面安排:开一个RadRails,开一个浏览器,开一个日志查看器.开一个http://api.rubyonrails.org 作为Rails参考手册.

Posted in  | 4 comments

学习Ruby on Rails

Posted by Captain Zhan Thu, 26 Oct 2006 08:57:00 GMT


学习使用教材<Agile Web Development with Rails>2nd beta
学习Ruby on Rails原因: 
1.开发效率高.
2.强大应变能力.
3.最超前的编程思想.
4.最时尚的网络编辑解决方案.

Posted in  | 1 comment

Older posts: 1 ... 3 4 5 6