From the course: Adding Stripe Payments to Your Ruby on Rails Application

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Rendering PDF receipts

Rendering PDF receipts

- [Instructor] And of course, the last thing we need to do is create a route for that charge download path. So let's have charges as a resource. And we can create a file called app/controllers/charges_controller.rb. This will be a class charges controller inherits from application controller. Before action will authenticate user. And we'll have our show action. This can be empty because we will also add before action, set charge. And we'll make that method down here. Set charge, @charge = current-user.charges.find(params[:id]). So this is pretty straightforward. This is your typical controller, except we need to add a PDF response to our show action. We'll use the respond to block in order to add the format.pdf response in here. And this is similar to the way that the HTML and JSON response formats work. But this time, we'll add a PDF format in. And we can send data back to the browser by saying @charge.receipt.render. This will create that PDF and make it a string, where we can…

Contents