Created
August 16, 2012 03:59
-
-
Save hidakatsuya/3366588 to your computer and use it in GitHub Desktop.
How to show PDF in browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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