基于ROR(ruby on Rails)的小型记账系统

来源:互联网 发布:淘宝店铺运营服务商 编辑:程序博客网 时间:2024/05/01 20:32

前记

        刚开始单位的人数比较少,记账还不是很困难,因为大家都一起吃饭,一般情况下都是平均一个价。可是后来新同事越来越多,吃饭也分成了多个小组,有人吃炒菜,有人吃面,饺子。吃炒菜还好计算,就是总消费除以人数,但是吃面和饺子就比较麻烦了,每个人的价格根据吃的量决定。人多了,算起来就复杂了,所以需要一个记账系统,让电脑来完成复杂的计算问题。

 

选择ROR

        Rails 是基于ruby的一个web应用开发的框架,有了这个框架,开发web应用就变得非常容易,只需要针对自己的应用做一些特定的编程。rails 自带web服务器,数据库采用sqlite3。

 

创建depot应用

1. 安装ruby, rubygems, rails:

#gem install rails --version 3.0.0

2. 创建depot应用:

#cd /opt/web-app/

#rails depot

 

开发记账系统

需求:

1. 帐号创建,删除,修改(用户名,密码,邮箱|user/new, user/del, user/edit)

2. 用户登录(admin/login)

2. 充值(可多选,每人充值一样的金额,发邮件给充值了的人|admin/charge)

3. 消费(给出总额,选择多人,取得平均消费额,减掉消费额,发邮件给相关人|admin/consume)

4. 查看余额(列出所有人的余额|admin/list_all)

 

开发:

1. generate controllers:

admin_controller.rb

depot> ruby script/generate controller admin login logout index consume charge list_all

users_controller.rb

depot> ruby script/generate controller user new edit del

 

2. views:

admin

           -login.html.erb(login page for user to login)

           -index.html.erb(shows the account info the logined user, also links: "logout", if he is admin, it wil also show "consume", "charge", “users", "list_all")

           -list_all.html.erb(list all account infos for all users)

           -consume.html.erb(input total cost, select attendees, submit)

           -charge.html.erb(input charge count, select who charges, submit)

layouts

         -admin.html.erb 

         -user.html.erb

users

          - edit.html.erb

          -index.html.erb

          -new.html.erb

          -show.html.erb

3. db tables:

users

groups

accouts

 

4. add sending mail functions when cosume or charge some money.

 采用本机作为SMTP服务器(需要安装postfix),外网,内网邮件发送测试通过。     

 

遇到的问题

【过程中depot.css老是不起作用,ERROR NoMethodError: private method `gsub!' called 】

To continue using Webrick, instead of switching to Mongrel, you can also
just edit line 15 of lib/ruby/1.8/webrick/htmlutils.rb to read

      str = string ? string.to_s.dup : ""

The problem is that NotModified exception is getting passed to
HTMLUtils::escape as a class, rather than a string (originally raised in
HTTPServlet::DefaultFileHandler). Since the only things that can really
be HTML escaped are strings, it should be safe to always convert the
input to string.

 

原创粉丝点击