"无效请求cookie的"错误

时间:2014-11-26 00:21:43

标签: ruby-on-rails ruby-on-rails-4 devise recaptcha

因此,出于某种原因,我在尝试提交ReCaptcha时收到了“invalid-request-cookie”。我正在使用ReCaptcha gem

我做错了什么?

另外,我的bash_profile中有我的ReCaptcha公钥和私钥,因此不应该是一个问题。

UsersStepsController.rb

class UserStepsController < ApplicationController

  def show
  end

  def update
    @user = current_user 
    captcha_message = "The data you entered for the CAPTCHA wasn't correct.  Please try again"
    if !verify_recaptcha(message: captcha_message)
      render :add_recaptcha
      else
       redirect_to root_path and return
    end
  end

  def add_recaptcha 
    @user = current_user
  end

end

的routes.rb

  patch '/user_steps', to: 'user_steps#update', as: 'update_user_steps'
  resources :user_steps, except: [:update]
  get '/add_recaptcha', to: 'user_steps#add_recaptcha'

user_steps / add_captcha.html.erb

<fieldset class="clearfix">
  <div class="g-recaptcha" data-sitekey="6LeUQ_xxxx_etc"></div>
  <div align="center"><%= recaptcha_tags :public_key => ENV['RECAPTCHA_PUBLIC_KEY'] %></div>
  <%= form_for(@user, {url: update_user_steps_path(id: @user.to_param)}) do |f| %>
  <br> 
  <%= f.submit "Done", class: "styling" %>
  <% end %>
  </div>
</fieldset>

更新日志:

Started PATCH "/user_steps?id=35" for 127.0.0.1 at 2014-11-26 11:55:52 -0500
Started PATCH "/user_steps?id=35" for 127.0.0.1 at 2014-11-26 11:55:52 -0500
Processing by UserStepsController#update as HTML
Processing by UserStepsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"sEOPI8KVuXLPSLjXVajF8QcWeLcUpibgHq6hHqgtwGA=", "commit"=>"Done", "id"=>"35"}
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"sEOPI8KVuXLPSLjXVajF8QcWeLcUpibgHq6hHqgtwGA=", "commit"=>"Done", "id"=>"35"}
  User Load (0.8ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 35  ORDER BY "users"."id" ASC LIMIT 1
  User Load (0.8ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 35  ORDER BY "users"."id" ASC LIMIT 1
  Rendered layouts/_messages.html.erb (0.1ms)
  Rendered layouts/_messages.html.erb (0.1ms)
  Rendered layouts/headers/_header_sign_up_step2.html.erb (0.2ms)
  Rendered layouts/headers/_header_sign_up_step2.html.erb (0.2ms)
  Rendered user_steps/add_recaptcha.html.erb within layouts/application (28.2ms)
  Rendered user_steps/add_recaptcha.html.erb within layouts/application (28.2ms)
Completed 200 OK in 919ms (Views: 800.4ms | ActiveRecord: 0.8ms)
Completed 200 OK in 919ms (Views: 800.4ms | ActiveRecord: 0.8ms)

1 个答案:

答案 0 :(得分:1)

以下是您的回答:)您需要在表单中包含该内容,除非该值不会被保存!

<fieldset class="clearfix">
  <%= form_for(@user, {url: update_user_steps_path(id: @user.to_param)}) do |f| %>
    <div align="center"><%= recaptcha_tags :public_key => ENV['RECAPTCHA_PUBLIC_KEY'] %></div>
  <br> 
  <%= f.submit "Done", class: "styling" %>
  <% end %>
  </div>
</fieldset>