Ruby Ruport实践—报表参数实现
此例子在 Ruby Ruport实践—简单报表系统 及 Ruby Ruport实践—中文PDF报表之PRAWN 的基础上进行完善,添加了对报表参数的设计及实现。
一、创建数据表report_parameters
create table report_parameters
(report_parameter_id integer not null auto_increment,
report_execute_id integer not null,
parameter_name varchar(240),
parameter_value varchar(240),
primary key "report_parameter_id")
ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
二、修改controllers/ReportExecutionsController.rb
将report_parameters的基本操作添加到report_executions界面
class ReportExecutionsController < ApplicationController
# GET /report_executions
# GET /report_executions.xml
Ruport::Formatter::Template.create(:simple) do |format|
eval("format.page = {:layout => :landscape}
format.grouping = {:style => :separated}
format.text = {:font_size => 20,:justification => :center}
format.table = {:font_size => 10,:heading_font_size => 10,:maximum_width => 720,:width => 720}
format.column = {:alignment => :center}
format.heading = {:alignment => :center,:bold => true,:font_size=>10}")
end
def show_report_details
report_execution = ReportExecution.find_by_execute_code(params[:report_execute_code])
@report_execute_code = params[:report_execute_code]
puts "======================显示报表参数======================="
@report_params = ReportExecution.find_by_sql("SELECT * from report_parameters WHERE report_execute_id= #{report_execution.report_execute_id}")
@report_params.each do |t|
puts "#{t.parameter_name}: #{t.parameter_value}"
end
puts"========================================================"
render :action => "execute"
end
def output_report
puts "----------------------------Output Report Code: #{params[:execution_code]}"
report_execution = ReportExecution.find_by_execute_code(params[:execution_code])
rep
相关文档:
Ruby 类的继承
关键字: Ruby 类的继承
一、普通方式的继承
Ruby只支持单继承
ruby 代码
class
Child < Father
......
end
Object是所有类的始祖,并且Object的实例方法 ......
http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
Understanding Ruby Blocks, Procs and Lambdas
Blocks, Procs and lambdas (referred to as closures
in Computer Science) are one of the most powerful aspects of Ruby, and
also one of the most misunderstood. This ......
Ruport是一个免费的Ruby报表工具,它可以令到制作报表软件变得简单一些。Ruport支持从文件或者数据库获得数据,提供工具操作数据。额外地,Ruport支持高扩展的格式化软件,目前能够支援HTML、PDF、CSV和文本输出。
Ruport可能是Ruby目前唯一的报表工具,目前在持续开发中,更多的新特性正在添加。
安装方法:
gem instal ......
Ruport中pdf_writer对中文的支持并不好,输出的中文显示的是乱码。上网查了很多资料,也没有找到好的解决方案,无奈只好查看源代码,到底为什么Ruport自带的PDF工具不支持中文输出。
Ruport::Formatter::PDF::Writer中找到以下代码
metrics = load_font_metrics(font)
metrics = PDF::Writer: ......
1. 安装Cygwin
运行Cygwin的安装程序。从文见包的的列表中,在DEV里面,确定要选择
• Ruby
• gcc
• subversion
你需要使用gcc来建立Cygwin版本的MySQL.
2. 在windows上面安装MYSQL:
download MySQL 5.0 Windows Installer
3. & ......