I currently have a rails app(4.2.1) that uses wicked_pdf and carrierwave functionality. The user currently clicks a button that renders a Family Assessment view to PDF, the user then downloads the PDF to their computer and navigates to an Assessment form where they then submit the PDF and it uploads successfully to AWS.
This all works fine however what I would like to do is "simplify" this process. When the user clicks a button the PDF would then be created and passed off to carrierwave for the upload to AWS using carrierwave/fog. I have a view now with a link to a controller which calls the FamilyAssesment.upload_assessment method.
I have been experimenting with different approaches but just can't seem to understand exactly what I need to do to get this to work.
Button on view
<%= link_to "Upload", family_assessment_pdf_upload_url(id: "#{f.object.case.id}"), class: 'button radius default tiny pdf-button' %>
family_assessments_controller.rb
class FamilyAssessmentsController < ApplicationController
def family_assessment_pdf_upload
c = Case.find(params[:id])
family_assessment = c.family_assessment
assessment = c.assessments.where(title: 'Families First Assessment').first
FamilyAssessment.upload_assessment(assessment, family_assessment)
#If work is done and url saved to assessment.assessment do some redirect action here
end
end
family_assessment.rb
class FamilyAssessment < ActiveRecord::Base
def self.upload_assessment(assessment, family_assessment)
family_assessment = family_assessment
assessment = assessment
#I think this is how I would create the PDF in preparation for hand off to carrierwave
pdf = WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "family_assessment",:template => 'family_assessments/family_assessment.pdf.erb', :locals => {:family_assessment => family_assessment})
)
#Pass pdf to carrierwave and save url in assessment.assessment
end
end