I'm trying out the dossier gem for reporting.
https://github.com/adamhunter/dossier
Can't seem to find in any of the docs how to send over a url variable like reports/test.csv?id=1
Have tried a few things, either get errors or blank values.
I'm trying out the dossier gem for reporting.
https://github.com/adamhunter/dossier
Can't seem to find in any of the docs how to send over a url variable like reports/test.csv?id=1
Have tried a few things, either get errors or blank values.
Your URL will need to look something like:
http://www.example.com/reports/test?options[id]=1
and you'll add a method with the same name as your option, in this case id
to your report in order to capture that URL parameter:
class TestReport < Dossier::Report
def sql
"SELECT * FROM foos WHERE id = :id"
end
def id
options[:id]
end
end
This answer probably comes a bit too late but I thought I'd share for future googlers.
tl;dr
/report/test?options[p1]=v1&options[p2]=v2
will be available inside theTestReport
instance asoptions[:p1] # => 'v1'
andoptions[:p2] # => 'v2'
Explanation:
When visiting a url such as
/reports/test.csv
you will triggerTestReport
to be instantiated and ultimately receive CSV output. If you would like to pass dynamic options in from the URL you would add them to the:options
parameter which will be passed by the controller to the instantiated report.All that is to say in the url use a format such as:
/reports/test.csv?options[id]=1&options[so_fancy]=true
. This will causeTestReport.new(id: '1', so_fancy: 'true')
to be called in the controller. Inside of the report instance you will be able to access these options via theoptions
hash. I personally usually write accessors for my options because this allows me to handle typecasting. All options come in as strings (because all controller parameters come in a strings).For example:
Hopefully this answers your question!