Skip to content

Instantly share code, notes, and snippets.

@hidakatsuya
Created August 16, 2012 03:59
Show Gist options
  • Save hidakatsuya/3366588 to your computer and use it in GitHub Desktop.
Save hidakatsuya/3366588 to your computer and use it in GitHub Desktop.
How to show PDF in browser
class TasksController < ApplicationController
def index
@tasks = Tasks.all
respond_to do |format|
format.html
# GET /tasks.pdf
# response as pdf
format.pdf do
report = ThinReports::Report.new :layout => 'tasks.tlf'
@tasks.each do |task|
report.list.add_row :name => task.name,
:due_date => task.due_date,
:done => task.done
end
send_data report.generate, :type => 'application/pdf',
:filename => 'tasks.pdf',
:disposition => 'inline' # set 'inline' (default 'attachment')
end
end
end
# :
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment