Created
October 7, 2012 05:06
-
-
Save louridas/3847173 to your computer and use it in GitHub Desktop.
changing output format based on submission-passed paramater
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
#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