简体   繁体   English

Rails 4,recaptcha和turbolinks

[英]Rails 4, recaptcha and turbolinks

I'm trying to implement recaptcha in one of my forms. 我正在尝试以我的一种形式实现Recaptcha。 I'm using the code below in my form 我在表单中使用以下代码

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

If I follow a link onto the page that contains the recaptcha, it isn't shown. 如果我点击包含该recaptcha的页面上的链接,则不会显示该链接。 If I then reload the page using the browser then it is shown. 如果然后使用浏览器重新加载页面,则会显示该页面。

I've figured it out that this is due to using turbolinks. 我已经知道这是由于使用了turbolinks。

I know placing data-no-turbolink in the body tag prevents turbolinks for that page and this works, but I'm not sure if this is the proper way to do it and if i want to disable it for the whole page just to get recpatcha working (seems hacky). 我知道在body标签中放置data-no-turbolink阻止该页面的turbolink,这是可行的,但是我不确定这是否是正确的方法,并且我是否想禁用整个页面只是为了获得Recpatcha工作(似乎很hacky)。

I also enclosed the recaptcha code in a div and put data-no-turbolink in the tag but that didn't work. 我也将recaptcha代码封装在div中,然后将data-no-turbolink放入标记中,但这没有用。

Is there a way to disable turbolinks just for the form with the recaptcha or is there another way I should be trying to solve this? 有没有一种方法可以仅针对带有Recaptcha的表单禁用涡轮链接,或者还有另一种我应该尝试解决的方法?

I had the same issue. 我遇到过同样的问题。 Here it is: https://github.com/ambethia/recaptcha/issues/83 在这里是: https : //github.com/ambethia/recaptcha/issues/83

Disabled turbolinks for the whole page. 整个页面禁用涡轮链接。

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

To whom it may concern - there is also a simple ajax fix according to the bug report on github ( http://github.com/ambethia/recaptcha/issues/83#issuecomment-30019798 ). 可能会涉及到的人-根据github上的错误报告( http://github.com/ambethia/recaptcha/issues/83#issuecomment-30019798 ),还有一个简单的Ajax修复程序。

Simply use: 只需使用:

<%= recaptcha_tags ajax: true %> 

Worked just fine for me! 对我来说工作很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM