Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.
This repository was archived by the owner on Oct 17, 2025. It is now read-only.

Question: Is it possible to pass my own arguments into the constructor for a report? #54

@PRAgarawal

Description

@PRAgarawal

In my ApplicationController, I have a generic index action [that can be overridden by any controller] where I want to return the CSV for any object with something like this:

def index
  @records = apply_page_query_parameters(policy_scope(resource_class))
  respond_to do |format|
    format.html { render_records(@records) }
    format.csv {
      report = GenericReport.new(project: @all_records, table: resource_class)
      send_data generate_csv_from_report(report.results)
    }
  end
end

But I can't seem to figure out how to pass in that table parameter, which I'd like to use in a GenericReport class kind of like this:

class GenericReport < Dossier::Report
  def sql
    'SELECT * FROM table <= :table'
  end
end

Would appreciate some help! And while I'm here, is there a way to generate the CSV from a report object directly? I wrote the generate_csv_from_report function myself in a helper I created. It was a very small and simple method, but it would be nice to eliminate it entirely.

For the record, the reason I do this instead of redirecting to the dossier reports route is that it was far easier to authorize access to a report this way when using the pundit gem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions