【问题标题】:Is there a ridiculously easy report plugin for rails?是否有一个非常简单的 Rails 报告插件?
【发布时间】:2010-07-31 17:13:23
【问题描述】:

为 Rails 应用程序重写报告代码已经过时了。你必须创建查询、路由、操作和视图......(是的,我很懒)有什么可以用更少的步骤创建完整的报告吗?

这是我认为理想的情况:

您有一个报告记录,其中包含名称、查询代码(在 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 不兼容,老实说,它有点笨拙。

【问题讨论】:

  • 有没有人认为这可能是个好主意? (或一个可怕的想法?)

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


【解决方案1】:

这让我们快到了:

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 生成图表。

【讨论】:

  • 噢!我想这已经很接近了。
  • 这是一个不错的插件,但今天不支持,最后一次提交是 4 年前。
【解决方案2】:

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

看看

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    相关资源
    最近更新 更多