rails有一个非常简单的报告插件吗?

时间:2010-07-31 17:13:23

标签: ruby-on-rails reporting report ruby-on-rails-plugins

它正在为Rails应用程序重新编写报告代码。 Ya必须创建查询,路由,操作和视图......(是的,我很懒)是否还有什么可以用更少的步骤创建完整的报告?

这是我想象的理想选择:

你有一个Report记录,它有一个名字,查询代码(用Ruby或SQL),也许有一些报告选项如下:

Report.create(:name  => "With last name 'smith'",
              :query => "Person.where( :last_name => 'smith' )")

这将存储一条记录,您将动态获取路线:

method  :  report_with_last_name_smith_path
http    :  GET  
url     :  /report_with_last_name_smith
options :   {
              :controller => 'reports', 
              :action => 'with_last_name_smith'
            }

报告记录将从查询中检索所有列(恰好是全部 这种情况下在people表中的列),并生成一个包含数据的视图(假装这是html):

 | First Name | Last Name | Date of Birth | Sex    | 
 | Bob        | Smith     | 03-13-2000    | Male   | 
 | Lisa       | Smith     | 03-23-1980    | Female | 
 | Jack       | Smith     | 03-13-1975    | Male   | 

任何人都知道插件有助于实现至少部分内容吗?

顺便说一句,Ruport gem可能与Rails 3不兼容,说实话,它有点笨拙。

2 个答案:

答案 0 :(得分:3)

这些东西让我们几乎到处:

http://github.com/wayneeseguin/dynamic_reports

在动态报告中,您可以创建一个指定一些参数的报告类,并添加控制器操作以指定用于结果的查询。

以下是网站上的示例:

# In some class that you create
class OrdersReport < DynamicReports::Report
  title "Orders Report"
  subtitle "All orders recorded in database"
  columns :total, :created_at

  link :total, '/report/item_sales?id={id}'   # =>  Will substitute ID for the value of ID associated with that record
end

# In any controller of your choosing:
def orders
  @orders = Order.find(:all, :limit => 25)
  render :text => OrdersReport.on(@orders).to_html, :layout => "application"
end

文档没有说明路线,所以我认为我们必须自己创建。

它还允许您使用所需的任何布局或自定义模板,并使用Google图表API生成图表。

答案 1 :(得分:0)

在我的项目中,我使用ransack gem,它非常棒,它允许用户进行自定义查询,并且您可以自定义可用的属性。

看看