Sonny Black
Sonny Black

Reputation: 1617

"invalid-request-cookie" error

So for some reason I'm getting a "invalid-request-cookie" when trying to submit a ReCaptcha. I'm using the ReCaptcha gem.

What am I doing wrong?

Also, I have my ReCaptcha public and private keys in my bash_profile so that shouldn't be an issue.

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>

Update Logs:

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)

Upvotes: 0

Views: 191

Answers (1)

Rubyrider
Rubyrider

Reputation: 3587

Here is your answer :) You need to include that inside your form unless the value won't be saved!

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

Upvotes: 1

Related Questions