reasoncorp/dossier

Listing out all reports

williscool opened this issue · 2 comments

Not enough testing for a pull request but not an issue because I have a solution.

Just sharing.

if you would like to list out all of your reports you can do

@report_names = Pathname.glob('app/reports/*').map{|f| f.basename("_report.rb")}.collect(&:to_s)

then in your view you can use

 <li> <%= link_to report_name.titleize, dossier_report_path( report: report_name ) %> </li>

I've been meaning to look into this for sometime and I've recently realized that ActiveSupport provides Class.subclasses

In your view you can do this:

%ul
  - Dossier::Report.subclasses.each do |report_class|
    %li= link_to report_class.report_name, dossier_report_path(report: report_name)

Thank you for sharing though!

The caveat with subclasses is that it only includes those that are loaded in memory. In Rails production, this will be everything, but in development, where things are loaded and unloaded dynamically, you can get erratic behavior.