Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a template and replace placeholders dynamically in Ruby On Rails

I have a set template in which there is address informations and other set of user information.

I have created a html file in the public folder and load the file at runtime and use

template = File.read("public/filename.html")
template % {key:value}

to replace the tokens with actual value and process as required.

Can anyone please let me know if its the correct way to do this, or are there any better ways like placing the template in other folders like views, bin etc?

like image 530
opensource-developer Avatar asked Mar 12 '26 03:03

opensource-developer


1 Answers

I would use wicked_pdf. After you've installed it, create a new route and controller that will take your user/address info as params and pass them as an instance variable into your template. From there, you can can template the pdf just like a regular view.

like image 131
teacher Avatar answered Mar 13 '26 16:03

teacher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!