Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 formµÄÁ½ÖÖд·¨

ÏÂÃæ½éÉÜRuby formµÄÁ½ÖÖд·¨¡£
Ruby formд·¨Ò»£ºÊ¹ÓÃform_for
< % form_for :order, :url => { :action => :save_order } do |form| %>   < p>    < %= label :order ......

Ruby On Rails 2.0.2Ô´´úÂë·ÖÎö£¨3£© named route


ǰÑÔ
  ÔÚ¡¶RoutingµÄÔØÈë¡·ÖУ¬ÎÒ´óÖ½éÉÜÁËÒ»ÏÂRailsÖÐ×î¼òµ¥µÄrouteÊÇÈçºÎ¼ÓÔØµÄ¡£ÕâÆªÎÄÕ£¬ÎÒ½«À´½²Ò»½²RailsϵͳÖиüΪ¸´ÔÓµÄnamed routeºÍÓëRESTfulÏà¹ØµÄresourceÊÇÈçºÎ±»¼ÓÔØµÄ¡£ÎªÁ˲»Öظ´Ì«¶àµÄ±ÊÄ«£¬ÕâÆªÎÄÕ½«ÔÚǰÎĵĻù´¡ÉϽøÐУ¬Èç¹û·¢ÏÖµ¥¶À¿´´ËÎÄʱ£¬ÓÐÉÙÐíÔÆÀïÎíÀ½¨ÒéÏÈ¿´Ò»¿´ÎÒµÄǰƪÎÄÕ£ºR ......

RUBYʵ¼ù—´øÃÜÂë¼ÓÃܵÄÓû§´´½¨¼°ÐÞ¸Ä

¿ª·¢»·¾³
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
Íê³Éºó½«×Ô¶¯Éú³ÉÏàÓ¦µÄÎ ......

Use lambda in Ruby ¾ÅͲһÌõ

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 ......

Ruby ±¨±í¹¤¾ß Ruport

RuportÊÇÒ»¸öÃâ·ÑµÄRuby±¨±í¹¤¾ß£¬Ëü¿ÉÒÔÁîµ½ÖÆ×÷±¨±íÈí¼þ±äµÃ¼òµ¥Ò»Ð©¡£RuportÖ§³Ö´ÓÎļþ»òÕßÊý¾Ý¿â»ñµÃÊý¾Ý£¬Ìṩ¹¤¾ß²Ù×÷Êý¾Ý¡£¶îÍâµØ£¬RuportÖ§³Ö¸ßÀ©Õ¹µÄ¸ñʽ»¯Èí¼þ£¬Ä¿Ç°Äܹ»Ö§Ô®HTML¡¢PDF¡¢CSVºÍÎı¾Êä³ö¡£
Ruport¿ÉÄÜÊÇRubyĿǰΨһµÄ±¨±í¹¤¾ß£¬Ä¿Ç°ÔÚ³ÖÐø¿ª·¢ÖУ¬¸ü¶àµÄÐÂÌØÐÔÕýÔÚÌí¼Ó¡£
°²×°·½·¨£º
gem instal ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ