Ruby on Rails Saturday, June 13, 2015

Per http://apidock.com/rails/ActionController/MimeResponds/respond_with:
respond_with needs to be paired with respond_to

And the order of your respond_with matters: you should list format.pdf last

On Friday, June 12, 2015 at 12:42:13 PM UTC-4, itsmechlark wrote:
I'm using `wicked_pdf` to handle PDF response but rails use HTML response even I already set route form to "pdf".
The `pdf` mime type already been registered.

At controller:
respond_to :pdf, only: :show

# GET /documents/1
# GET /documents/1.pdf
def show
retrieve_document_search_hits(@document)
respond_with(@document) do |format|
format.pdf { render pdf: @document.display_text }
format.html
end
end

rails v4.2.1
responders v2.1.0


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8e30b263-df2b-46c1-be1f-be649a92e2f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment