提交表格时不检查验证码

时间:2019-04-03 16:32:50

标签: ruby-on-rails recaptcha

我在本地主机上的表单上设置了一个Recaptcha,但是我可以提交此表单而无需选中“我不是机器人”框。我正在尝试使用Ambethia / recaptcha宝石,但似乎无法使其正常工作。

我已按照指南进行操作,并浏览了网络上的多个视频和其他站点,但无法弄清楚我做错了什么。

这是我的表单,它是show.html.erb文件的一部分:

<% if @entry %>
  <% if @entry_result %>
    <p class="alert alert-success"><%= @entry.form.success_message %></p>
  <% else %>
    <%= simple_form_for(@entry) do |f| %>
      <%= f.error_notification %>
      <%= f.association :form, as: :hidden %>
      <%= render "form#{@entry.form.id}", entry: @entry, f: f %>
      <script src="https://www.google.com/recaptcha/api.js" async defer></script>
      <div class="g-recaptcha" data-sitekey="6Lch3ZkUAAAAAB3-KdNTF6_pLdeByzzdvvUveCcL"></div>
      <%= f.button :submit, value: 'Submit', class: 'btn btn-primary', data: { disable_with: 'Please wait...' } %>
    <% end %>
  <% end %>
<% end %>

这是我试图处理的pages_controller.rb文件的一部分:

 def show
    @post = Post.friendly.where(slug: params[:id]).first

    unless @post
      return redirect_to root_path
    end

    # Form at bottom of page
    @entry = false
    @entry_result = false
    if @post.form
      if session[:form_entry]
        @entry_result = session[:form_entry]
        verify_recaptcha(model: @entry) && session[:form_entry] = false
      end
      @entry = FormEntry.new(form: @post.form)
    end

我从一个不再在我公司工作的开发人员那里继承了这个应用程序,但据我所知,我正在寻找正确的文件/部分。我已经为“ model:@entry”部分尝试了许多不同的替代方法,但是似乎没有任何效果。我尝试过的所有操作仍然允许在不选中此框的情况下提交表单。任何帮助或见解将不胜感激,谢谢您的宝贵时间。

0 个答案:

没有答案
相关问题