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Èç¹û·¢ÏÖÎļþ¼ÐÖÐÓÐsystem£¬readonly£¬hideÀàÐ͵ÄÎļþ£¬ÔòÊDz»ÄÜÖ±½Óɾ³ý
ËûÃǵġ£ÈçºÎ½â¾öÄØ£¿
ÒÔÆäÈËÖ®µÀ»¹ÖÎÆäÈËÖ®Éí£¡
def dryf(fpath) #destroy file
x = Iconv.iconv('utf-8','gbk',fpath).to_s
%x{attrib -R -S -H \"#{Iconv.iconv('gbk','utf-8',x).to_s}\"}
f = File.new(f ......
¿ª·¢»·¾³£º
OS:Windows XP
Ruby:Ruby1.9.1
Rails:Rails2.3.5
will_paginate:will_paginate2.3.11
(ÔÚÃüÁîÐÐÖÐÔËÐÐ gem install mislav-will_paginate --source http://gems.github.com )
IDE:Rubymine2.0.1
DB:mysql5.0.9
±¾ÀýÔÚÉÏÒ»¸öÀý×Ó£¨Rubyʵ¼ù—¼òµ¥Êý¾Ý¿â²Ù×÷£©µÄ»ù´¡ÉÏʵÏÖ·ÖÒ³£¬ÀûÓõÄÊÇwill_p ......
require 'curses'
module Curses
def self.program
main_scr=init_screen
noecho
cbreak
curs_set(0)
main_scr.keypad=true
yield main_scr
end
end
Curses.program do |scr|
max_x=scr.maxx
max_y=scr.maxy
100.times do
scr.setpos(rand(max_y),rand(max_x))
......
¿ª·¢»·¾³
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
Íê³Éºó½«×Ô¶¯Éú³ÉÏàÓ¦µÄÎ ......