Rails 4, recaptcha and turbolinks



我正在尝试以我的一种形式实现recaptcha。我在表单中使用以下代码

<script type="text/javascript"
  src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
</script>
<noscript>
  <iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
     height="300" width="500" frameborder="0"></iframe><br>
   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
   </textarea>
   <input type="hidden" name="recaptcha_response_field"
     value="manual_challenge">
</noscript>

如果我点击链接进入包含验证码的页面,则不会显示该链接。如果我然后使用浏览器重新加载页面,则会显示它。

我已经弄清楚这是由于使用了涡轮链接。

我知道将data-no-turbolink放在 body 标签中会阻止该页面的涡轮链接,这有效,但我不确定这是否是正确的方法,以及我是否想为整个页面禁用它只是为了让 recpatcha 工作(似乎很hacky)。

我还将验证码包含在div 中,并将data-no-turbolink放入标签中,但这不起作用。

有没有办法仅为带有验证码的表单禁用涡轮链接,或者有没有另一种方法应该尝试解决这个问题?

我遇到了同样的问题。这是:https://github.com/ambethia/recaptcha/issues/83

禁用了整个页面的涡轮链接。

<%= link_to "Sign up", new_registration_path(resource_name), "data-no-turbolink" => true %><br />

它可能关注的人 - 根据 GitHub 上的错误报告,还有一个简单的 ajax 修复(http://github.com/ambethia/recaptcha/issues/83#issuecomment-30019798)。

只需使用:

<%= recaptcha_tags ajax: true %> 

对我来说工作得很好!

最新更新