'undefined method `render_to_string' for #<UpdateService:0x00007f900dbaa578>
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>
Solution 1:[1]
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 }
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sampat Badhe |
