Skip to content

Instantly share code, notes, and snippets.

@louridas
Created October 7, 2012 05:06
Show Gist options
  • Save louridas/3847173 to your computer and use it in GitHub Desktop.
Save louridas/3847173 to your computer and use it in GitHub Desktop.
changing output format based on submission-passed paramater
#incidents_controller.rb:
if params[:commit] == I18n.t(:text_search_results)
self.request.format = "text"
end
format.text do
self.response.headers["Content-Type"] ||= 'text/plain'
self.response.headers["Content-Disposition"] =
"attachment; filename=search.txt"
self.response.headers['Last-Modified'] = Time.now.ctime.to_s
self.response_body = Enumerator.new do |yielder|
@incidents.each do |incident|
yielder.yield incident.to_text + "\n"
end
end
end
# incidents viewer index.html.erb:
<%= submit_tag t(:text_search_results) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment