undefined method `render_to_string' for #<UpdateService:0x00007f900dbaa578>

410 views Asked by At
class UpdateService
 def initialize(user)
  @user = user
 end
 def user_onboarding(request_params)
    
      file = WickedPdf.new.pdf_from_string(
        ApplicationController.new.render_to_string(template: 'user_agreement.pdf.erb', locals: { lawyer: @lawyer }),
        footer: { content: render_to_string(template: 'footer.html.erb'), spacing: 10 },
        margin: { top: 10, bottom: 20 }
      )
      tempfile = Tempfile.new(["agreement", ".pdf"], Rails.root.join("tmp"))
      tempfile.binmode
      tempfile.write file
      tempfile.close
      @user.document = File.open(tempfile.path)
      tempfile.unlink
      @user.save
 end
end

I am getting this error below and to resolve it I added ApplicationController.new ahead of render_to_string but I am still getting this error. Please help me resolve it

undefined method `render_to_string' for #<UpdateService:0x00007f900dbaa578>
1

There are 1 answers

0
Sampat Badhe On

You should replace render_to_string with ApplicationController.new.render_to_string for the footer, just as you did for the first render_to_string call.

      file = WickedPdf.new.pdf_from_string(
        ApplicationController.new.render_to_string(template: 'user_agreement.pdf.erb', locals: { lawyer: @lawyer }),
        footer: { content: ApplicationController.new.render_to_string(template: 'footer.html.erb'), spacing: 10 },
        margin: { top: 10, bottom: 20 }
      )