Skip to content

Instantly share code, notes, and snippets.

@sathish316
Created May 24, 2012 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sathish316/2781117 to your computer and use it in GitHub Desktop.
Save sathish316/2781117 to your computer and use it in GitHub Desktop.
csv
def show
@results = Foo.all
respond_to do |format|
format.csv { render_csv "report"}
end
end
private
def render_csv(filename = nil)
filename += '.csv'
if request.env['HTTP_USER_AGENT'] =~ /msie/i
headers['Pragma'] = 'public'
headers["Content-type"] = "text/plain"
headers['Cache-Control'] = 'no-cache, must-revalidate, post-check=0, pre-check=0'
headers['Content-Disposition'] = "attachment; filename=\"#{filename}\""
headers['Expires'] = "0"
else
headers["Content-Type"] ||= 'text/csv'
headers["Content-Disposition"] = "attachment; filename=\"#{filename}\""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment