I’m having a problem with a controller that I’m writing to generate and return a PDF.
If I make a super basic HTML template like so:
<%= form_with url:'/card', method: :get, local: true do |form| %>
<%= form.textarea :id, size: "70x1" %>
<%= form.submit "Get PDF" %>
<% end %>
That is rendered on my landing “root” page, with nothing in the controller.
Where my route file looks like this:
get "/card", to: "card#get_pdf"
and my CardController:
class CardController < ActionController::Base
def get_pdf
..........
data = PdfHelper.generate(card_urls, "LETTER")
send_data data, :type => 'application/pdf', :disposition => 'attachment', :filename => 'test.pdf'
end
end
Everything works fine. I am able to click the button on the plain-html-only page and I am returned my generated PDF file.
I’m trying to add styling and JS to the main landing page. When I change my HomeController (with nothing in its methods) to
class HomeController < ApplicationController
Everything breaks - my button no longer downloads the PDF file anymore. I’m pretty stuck as to why. My application Controller is just the default
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
layout "application"
end
Please let me know if there is any further detail that could help debug this and thanks in advance. I’ve been fighting this for 2 days now and can’t figure out whats wrong.