Ruby Ruportʵ¼ù—¼òµ¥±¨±íϵͳ
¿ª·¢»·¾³
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
±¾ÀýÉè¼ÆµÄ±¨±íϵͳ¹¤×÷ÔÀíÈçͼ£¨´¿Êô¸öÈËÀí½â£©£¬ÒÔProducts±íΪÀý£º
½ÓÏÂÀ´ÊµÏÖµÄÀý×Ó½«ÀûÓÃeval·½·¨ÊµÏÖ¶¯Ì¬½Å±¾£¬¶Ô¿ÉÄܱ䶯µÄµØ·½Í¨¹ýÊý¾Ý¿â±£´æÔËÐÐʱ´úÂëƬ¶Ï
Ò»¡¢´´½¨±¨±íÔËÐÐʱÐèÒªµÄÊý¾Ý±í
Ö÷¼ü×Ô¶¯Ôö³¤
create table report_definitions
(report_definition_id integer not null,
report_code varchar(30),
report_name varchar(240),
report_sql varchar(4000),
basic_model varchar(20),
primary key ('report_definition_id'));
create table report_templates
(report_template_id integer not null,
template_code varchar(30),
template_name varchar(240),
template_content varchar(4000),
template_type varchar(10),
primary key ('report_template_id'));
create table report_executions
(report_execute_id integer not null,
execute_code varchar(30),
execute_name varchar(240),
report_definition_id int not null,
report_template_id int not null
primary key ('report_execute_id'));
create table products
(product_id int not null,
title varchar(100),
description varchar(100),
price int,
primary key('product_id'));
¶þ¡¢ÔÚRubyMineÖÐÀûÓÃScaffold·½·¨Éú³ÉÊý¾Ý±í¶ÔÓ¦µÄÎļþ£¨°üÀ¨Model,View,ControllerµÈ£©
Èý¡¢ÐÞ¸Äenvrioment.rb
ÔÚĩβÌí¼Ó
require "rubygems"
require "ruport"
ËÄ¡¢ÐÞ¸ÄProducts.rb
ÔÚÆäÖÐÌí¼Ó
acts_as_reportable
ʹÆäÄÜʹÓÃacts_as_reportableÖÐÌṩµÄ·½·¨
Îå¡¢´´½¨ReportOuptController£¬´úÂëÈçÏ£º
class ReportOutputController< Ruport::Controller
#Code here
stage :data_sheet
def setup
puts "basic_model= #{options[:basicModel]}"
self.data = eval(options[:basicModel]).report_table_by_sql(options[:sql])
end
end
class ReportHtml < Ruport::Formatter::PDF
renders :pdf, :for => ReportOutputController
build :data_sheet do
eval(options[:outputContent])
end
end
class ReportPdf < Ruport::Formatter
Ïà¹ØÎĵµ£º
¿ª·¢»·¾³£º
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 ......
ʹÓà will_paginate ½øÐзÖÒ³ºÍ¼òµ¥²éѯ
ÔÚÃüÁîÐÐÏÂʹÓà gem install will_paginate ÃüÁ³öÏÖÏÂÃæ½á¹û°²×°³É¹¦
´ò¿ª books_controller.rb (Äã×Ô¼ºµÄ¿ØÖÆÆ÷)
×¢Ê͵ô²éÕÒÈ«²¿µÄ·½·¨£¬Ê¹ÓÃÏÂÃæµÄ·½·¨£¬ÒѾ¼¯³É¸ù¾Ýtitle½øÐвéѯ
Ruby´úÂë
#@books = Book.all
@books = Book.pagina ......
ruby³£¹æ·ÃÎÊaccessÊý¾Ý¿âµÄ·½·¨Ó¦¸ÃÊÇʹÓÃDBI¿â
£º
require 'dbi'
DBI.connect("DBI:ADO:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;")
¿ÉÊÇ
¼òµ¥³¢ÊÔÖ®ºóûÄܳɹ¦£¬ÌáʾÕÒ²»µ½Çý¶¯Æ÷ADO,ÀÁµÃÔÙÊÔ£¬ËìÕÒÆäËû·½·¨¡£
Ò»·¬ËÑË÷Ö®ºó£¬·¢ÏÖ¿ÉÒÔÓÃWIN32OLEÀ´·ÃÎÊaccess,дһ¸ö¼òµ¥µÄÀà°ü×°Ö®:
......
¿ª·¢»·¾³
Ruby: Ruby1.9.1
Rails: Rails2.3.5
Mysql:Mysql5.0.9
Driver:mysql-2.8.1-x86-mingw32.gem
IDE:Rubymine2.0.1
Ò»¡¢´´½¨Êý¾Ý±íUsers
ÀûÓÃRubyMine×Ô´øµÄScaffold¹¤¾ß´´½¨Êý¾Ý±íUsers£¬Ò²¿ÉÒÔÊÖ¶¯´´½¨
¶þ¡¢´´½¨ControllerºÍView
RubyÏîÄ¿—>ÓÒ¼ü—>Create Model
Íê³Éºó½«×Ô¶¯Éú³ÉÏàÓ¦µÄÎ ......
%{String} ÓÃÓÚ´´½¨Ò»¸öʹÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´®
%Q{String} ÓÃÓÚ´´½¨Ò»¸öʹÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´®
%Q!Some String of “Characters”! <==> ” Some String of \”Characters\” “
%q{String} ÓÃÓÚ´´½¨Ò»¸öʹÓõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Ö·û´®
%q!Som ......