Skip to content

Instantly share code, notes, and snippets.

@jeremiaheb
Last active December 18, 2015 03:49
Show Gist options
  • Save jeremiaheb/5721094 to your computer and use it in GitHub Desktop.
Save jeremiaheb/5721094 to your computer and use it in GitHub Desktop.
create a pdf of all samples
SamplesController ---
def index
if current_diver.role == 'admin'
@samples = Sample.all
elsif current_diver.role == 'manager'
@samples = Sample.joins(:diver_samples).where( "diver_samples.diver_id=? AND diver_samples.primary_diver=? OR boatlog_manager_id=?", current_diver, true, current_diver.boatlog_manager_id ).uniq
else
@samples = current_diver.samples.merge(DiverSample.primary)
end
@proofing_samples = current_diver.samples.merge(DiverSample.primary)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @samples }
format.csv { send_data Sample.to_csv }
format.xls
format.pdf do
pdf = SamplePdf.new(@proofing_samples)
send_data pdf.render, filename: "#{current_diver.whole_name}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
end
class SamplePdf < Prawn::Document
def initialize(samples)
super(margin: 2)
samples.each do |sample|
@sample = sample
sample_head
substrate_slope
max_vert_relief
surface_relief_perc
blank1
abiotic_footprint
blank2
comments
biotic_cover
species_data_27
if @sample.sample_animals.length > 27
species_data_54
end
start_new_page
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment