<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Right Traq Blog comments on Rails Reporting with acts_as_reportable</title>
    <link>http://www.righttraq.com/blog/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Right Traq Blog comments</description>
    <item>
      <title>"Rails Reporting with acts_as_reportable" by flinn</title>
      <description>&lt;p&gt;One of the biggest missing features of Rails has been the lack of a reporting tool.  Dynamic reporting is a pain in just about any language, but particularly with Rails because of predefined views and railsish renderings.  Views are great when working with predefined sets of data derived from ActiveRecord.&lt;/p&gt;


	&lt;p&gt;Unfortunately it isn&amp;#8217;t easy to dynamically query and render resulting data sets.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://ruport.rubyforge.org/"&gt;Ruport&lt;/a&gt; has been around for some time now, but until now hasn&amp;#8217;t had a sweet rails plugin to convert ActiveRecord data to ruport data collections.&lt;/p&gt;


	&lt;p&gt;Along comes &lt;a href="http://stonecode.svnrepository.com/acts_as_reportable/trac.cgi"&gt;acts_as_reportable&lt;/a&gt;...&lt;/p&gt;


	&lt;p&gt;With acts_as_reportable you can do really cool stuff like this:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
class Part &amp;lt; ActiveRecord::Base
  acts_as_reportable
  belongs_to :account
  belongs_to :category
end

class Category &amp;lt; ActiveRecord::Base
  acts_as_reportable
  has_many :parts
end

class Account &amp;lt; ActiveRecord::Base
  acts_as_reportable
  has_many :parts
  has_many :categories, :through =&amp;gt; :parts
end

class ReportsController &amp;lt; ApplicationController
  def index
    parts = Part.report_table(:all, :include =&amp;gt; [:account, :category])

    # Remove non content columns
    parts.column_names.each{ |c| parts.remove_column(:name =&amp;gt; c) if c =~ /(.id|_id|_count)$/ }

    # Convert table headings
    parts.column_names = parts.column_names.collect{ |cn| cn.gsub(/\./, ' ').titleize }

    render :text =&amp;gt; parts.as(:html), :layout =&amp;gt; true
  end
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;a href="/reports-index.html"&gt;See the results here&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;The possibilities here are pretty awesome.  To make this work really well, we could very easily create a form to add conditions to a find.  Combine it with something like the &lt;a href="http://agilewebdevelopment.com/plugins/ez_where"&gt;ez_where&lt;/a&gt; plugin and you&amp;#8217;ve got some pretty powerful reporting functionality.&lt;/p&gt;

</description>
      <pubDate>Wed, 31 Jan 2007 21:25:00 EST</pubDate>
      <guid>&lt;a href="/blog/articles/2007/01/31/rails-reporting-with-acts_as_reportable"&gt;Rails Reporting with acts_as_reportable&lt;/a&gt;</guid>
      <link>&lt;a href="/blog/articles/2007/01/31/rails-reporting-with-acts_as_reportable"&gt;Rails Reporting with acts_as_reportable&lt;/a&gt;</link>
    </item>
  </channel>
</rss>
