public
Created

Rails redirect using post emulation

  • Download Gist
redirect.rb
Ruby
1 2 3 4 5 6 7
# This code isn't safe; at least add escaping to the url and the params.
class ActionController::Base
def redirect_using_post(url, params)
render :text => %Q{<form action="#{url}">#{params.map{|k,v| %Q{<input type=
hidden" name="#{k}" value="#{v}" />}}.join('')}</form><script>document.forms[0].submit()</script>}
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.