Im creating an API that should generate a PDF based on some information on the database.
When trying to call the action im getting an error:
ActionController::UnknownFormat (ActionController::UnknownFormat):
app/controllers/v1/trips_controller.rb:56:in `print_monthly_trips'
This is my controllers:
/#application_controller.rb
class ApplicationController < ActionController::API
include Response
include ExceptionHandler
include Pundit
include ActionController::MimeResponds
/#trips_controler.rb
def print_monthly_trips
@trips_to_print = current_user.trips_for_month(3)
respond_to do |format|
format.html
format.pdf do
render pdf: "file_name",
template: "trips/report.html.erb",
layout: 'pdf.html'
end
format.json do
render pdf: "file_name",
template: "trips/report.html.erb",
layout: 'pdf.html'
end
end
end
My routes:
get 'print_monthly_trips', to: 'trips#print_monthly_trips'
Im calling my API with:
http GET https://localhost/print_monthly_trips Accept:'application/vnd.trips.v1+json' Authorization:'my_token'
So, why im getting this:
ActionController::UnknownFormat (ActionController::UnknownFormat):
app/controllers/v1/trips_controller.rb:56:in `print_monthly_trips'
Mime::Type
? Why are you requestingjson
and returning a PDF? Your layout looks wrong according to the docs – Afterword