I'm on Rails 2.3.3, and I need to make a link that sends a post request.
I have one that looks like this:
= link_to('Resend Email',
{:controller => 'account', :action => 'resend_confirm_email'},
{:method => :post} )
Which makes the appropriate JavaScript behavior on the link:
<a href="/account/resend_confirm_email"
onclick="var f = document.createElement('form');
f.style.display = 'none';
this.parentNode.appendChild(f);
f.method = 'POST';
f.action = this.href;
var s = document.createElement('input');
s.setAttribute('type', 'hidden');
s.setAttribute('name', 'authenticity_token');
s.setAttribute('value', 'EL9GYgLL6kdT/eIAzBritmB2OVZEXGRytPv3lcCdGhs=');
f.appendChild(s);
f.submit();
return false;">Resend Email</a>'
My controller action is working, and set to render nothing:
respond_to do |format|
format.all { render :nothing => true, :status => 200 }
end
But when I click the link, my browser downloads an empty text file named "resend_confirm_email."
What gives?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…