易截截图软件、单文件、免安装、纯绿色、仅160KB

RUBY实践—Ruby Report之Ruport简单应用

Ruport官方网站:http://www.rubyreports.org/
本例中将介绍Ruby报表的简单开发
开发环境
OS:WindowsXP
Ruby:Ruby1.8.7
Rails:Rails2.3.5
Mysql:Mysql5.0.9
IDE:Rubymine2.0.1
一、安装gem
安装命令
gem install ruport
gem install ruport-util
gem install acts_as_reportable
二、创建数据库
  database: dbdevelopment
  username: crystal
  password: crystal
  host: localhost
三、创建Rails工程RailsRuport
1)配置database.yml,内容如下:
development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: dbdevelopment
  pool: 5
  username: crystal
  password: crystal
  host: localhost
2)通过scaffold映射Products表
参数为 Product title:string description:string price:integer
3)修改routes.rb
修改
map.resources :products

map.resources :products,:collection=>{:save_as_report=>:get}
表示当遇到save_as_report时,用get方式,否则默认方式将跳转到show.html执行查询
在最后添加
require "rubygems"
require "ruport"
四、修改Product.rb
为Model添加acts_as_reportable方法
修改后代码如下:
class Product < ActiveRecord::Base
acts_as_reportable
set_primary_key "product_id"
end  
五、修改products_controller.rb
1)修改index方法为如下:添加Report的输出应用
def index
@products = Product.all
@table = Product.report_table(:all,:only=>['title','description'])
@grouping = @table.to_group('title')
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @products }
end
end
 
2)添加save_as_report方法,实现Report的保存应用
def save_as_report
puts 'Save Pdf!'
send_data Product.report_table(:all,:only=>['title','description']).to_pdf, :type => "application/pdf",
:filename => "books.pdf"
end
六、 修改app/view/products/index.html.erb
在界面上显示Report绘制的table,在最后添加如下代码:
<h2>Report Table</h2>
<%= @grouping.to_html %&


相关文档:

Ruby实践—连接Mysql

安装环境:
OS:Windows XP
Ruby: Ruby1.9.1
Mysql: Mysql5.1.46 (username/password: root/root  port:3306)
Ruby-Mysql Driver: mysql-2.8.1-x86-mswin32.gem
(注:用2.7.3版本的驱动在测试时会出现 require"mysql",找不到指定模块 错误)
IDE:RubyMine2.0.1
安装Ruby,RubyMine,Mysql的事项在这里就不多 ......

RUBY实践—数据库简单操作

开发环境:
Ruby:1.9.1
Rails:2.3.5
Rake:0.8.7
Rack:1.0.1
Mysql:5.0.9
Ruby-mysql:mysql-2.8.1-x86-mswin
IDE:RubyMine2.0.1
数据库准备:
database:dbdevelopment
user:crystal
password:crystal
一、创建Ruby项目RorTest
二、修改database.yml
这里只启用development环境数据库,修改配置文件如下:
dev ......

使用ruby与MS Access数据库交互

ruby常规访问access数据库的方法应该是使用DBI库

require 'dbi'

DBI.connect("DBI:ADO:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;")

可是
简单尝试之后没能成功,提示找不到驱动器ADO,懒得再试,遂找其他方法。
一番搜索之后,发现可以用WIN32OLE来访问access,写一个简单的类包装之: ......

ruby在windows 7 cmd 中显示彩色文字

先放上一个实例的bat文件,要求管理员特权运行:
@echo off
::CMD里显示彩色文字
chcp 437>nul&&graftabl 936>nul
if not exist CONFIG.NT copy %WinDir%\System32\CONFIG.NT CONFIG.NT
@cls
echo DEVICE=%WinDir%\System32\ANSI.SYS /x >%WinDir%\System32\CONFIG.NT
@echo.
command /cecho 
com ......

Watir 语法(Web Application Testing in Ruby)

Watir 语法(Web Application Testing in Ruby)
# watir的安装
watie的安装请查看 -> Ruby library的安装
# 使用Watir工具,需要在脚本中加上
require 'watir'
# 创建一个IE的实例
ie = Watir::IE.new
或者在创建的同时直接转到页面
ie = Watir::IE.start('http://www.text.com/')
Watir使用start方法 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号