michael
michael

Reputation: 145

rails respond_to pdf format

I'm following a tutorial to fill pdf and send to browser... but with error:

ActionController::UnknownFormat (ActionController::UnknownFormat):
  app/controllers/registries/customers_controller.rb:113:in `print_bollettino_2’

112  def print_bollettino_2
113    respond_to do |format|
114      format.pdf { send_file BollettinoUtente2Sezioni.new(@customer).export, type: 'application/pdf' }
115    end
116  end

Can you help me?

Many thanks,

regards

Upvotes: 0

Views: 1566

Answers (1)

Meri Alvarado
Meri Alvarado

Reputation: 191

If you will put a format.pdf in the respond_to, you need to declare the new format to config/initializers/mime_types.rb by adding:

Mime::Type.register "application/pdf", :pdf

But you can also implement it directly as:

def print_bollettino_2
   send_file BollettinoUtente2Sezioni.new(@customer).export, type: 'application/pdf'
end

You can also use:

send_data BollettinoUtente2Sezioni.new(@customer).export, type: 'application/pdf'

if the function for generation of pdf does not return a filepath.

Upvotes: 3

Related Questions