"渲染:无=>真"返回空的纯文本文件? [英] "render :nothing => true" returns empty plaintext file?

查看:30
本文介绍了"渲染:无=>真"返回空的纯文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Rails 2.3.3,我需要创建一个发送 post 请求的链接.

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} )

这使得链接上的 JavaScript 行为适当:

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

但是当我点击链接时,我的浏览器会下载一个名为resend_confirm_email"的空文本文件.

But when I click the link, my browser downloads an empty text file named "resend_confirm_email."

是什么?

推荐答案

更新:这是旧 Rails 版本的旧答案.对于 Rails 4+,请参阅下面的 William Denniss 的帖子.

在我看来,响应的内容类型不正确,或者在您的浏览器中没有正确解释.仔细检查您的 http 标头以查看响应的内容类型.

Sounds to me like the content type of the response isn't correct, or isn't correctly interpreted in your browser. Double check your http headers to see what content type the response is.

如果不是text/html,您可以尝试手动设置内容类型,如下所示:

If it's anything other than text/html, you can try to manually set the content type like this:

render :nothing => true, :status => 200, :content_type => 'text/html'

这篇关于&quot;渲染:无=&gt;真"返回空的纯文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆