Please help, i’m getting the following error:
ActionController::InvalidAuthenticityToken in UserController#register
ActionController::InvalidAuthenticityToken
RAILS_ROOT: /home/nick/Desktop/Learning_Rails/New_Rails
Application Trace | Framework Trace | Full Trace
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/request_forgery_protection.rb:79:in
verify_authenticity_token' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:178:in
send’
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:178:in
evaluate_method' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:166:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:225:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:629:in
run_before_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:615:in
call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:610:in
perform_action_without_benchmark’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17:in
ms’
/usr/lib/ruby/1.8/benchmark.rb:308:in realtime' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17:in
ms’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rescue.rb:160:in
perform_action_without_flash’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/flash.rb:141:in
perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523:in
send’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523:in
process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:606:in
process’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:391:in
process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:386:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:433:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:88:in
dispatch’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:111:in
_call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:82:in
initialize’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/head.rb:9:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/head.rb:9:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb:24:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/params_parser.rb:15:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rewindable_input.rb:25:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/abstract_store.rb:122:in
call’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:29:in
call' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in
cache’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:9:in
cache' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:28:in
call’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/reloader.rb:9:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/failsafe.rb:11:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in
synchronize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:106:in
call' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/static.rb:31:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:46:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:40:in
each’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:40:in
call' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/log_tailer.rb:17:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/content_length.rb:13:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/chunked.rb:15:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb:61:in
process' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in
process_client’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in each' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
process_client’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
initialize’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
run’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
new’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in run' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb:34:in
run’
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
require’
script/server:3
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/request_forgery_protection.rb:79:in
verify_authenticity_token' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:178:in
send’
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:178:in
evaluate_method' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:166:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:225:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:629:in
run_before_filters’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:615:in
call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:610:in
perform_action_without_benchmark’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17:in
ms’
/usr/lib/ruby/1.8/benchmark.rb:308:in realtime' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/benchmark.rb:17:in
ms’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rescue.rb:160:in
perform_action_without_flash’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/flash.rb:141:in
perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523:in
send’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:523:in
process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/filters.rb:606:in
process’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:391:in
process' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/base.rb:386:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/route_set.rb:433:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:88:in
dispatch’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:111:in
_call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:82:in
initialize’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/head.rb:9:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/head.rb:9:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb:24:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/params_parser.rb:15:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rewindable_input.rb:25:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/abstract_store.rb:122:in
call’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:29:in
call' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in
cache’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:9:in
cache' /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/query_cache.rb:28:in
call’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/reloader.rb:9:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/failsafe.rb:11:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in
synchronize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/lock.rb:11:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:106:in
call' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/static.rb:31:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:46:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:40:in
each’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb:40:in
call' /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/log_tailer.rb:17:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/content_length.rb:13:in
call' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/chunked.rb:15:in
call’
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb:61:in
process' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in
process_client’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in each' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
process_client’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in run' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
initialize’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in new' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
run’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
initialize' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
new’
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in run' /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb:34:in
run’
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in
require’
script/server:3
Request
Parameters:
{“commit”=>“Register!”,
“authenticity_token”=>“lx05SV8DFX/Pwkd53M9pxWgBB9P6mWbAlKOQgiB4O2Q=”,
“user”=>{“password”=>"",
“screen_name”=>"",
“email”=>""}}
Show session dump
Response
Headers:
{“Content-Type”=>"",
“Cache-Control”=>“no-cache”}
Ive been using the first printing of RailsSpace and have run into a few
compatibility issues along the way, usually due to outdated code.
However i’ve been able to fix those errors on my own. This time i
backtraced to try and place the error, and i backtraced all the way to a
state where i know it worked, and it continues to throw this exception.
here is my user_controller:
class UserController < ApplicationController
def index
@title = “RailsSpace User Hub”
end
def register
@title = “Register”
if request.post? and params[:user]
@user = User.new(params[:user])
if @user.save
flash[:notice]=“User #{@user.screen_name} created!”
redirect_to :action => “index”
end
end
end
end
and my user_controller_test:
require File.dirname(FILE) + ‘/…/test_helper’
require “user_controller”
#Re-raise errors caught by the controller
class UserController; def rescue_action(e) raise e end; end
class UserControllerTest < ActionController::TestCase
def setup
@controller = UserController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
# Make sure the registration page responds with the proper form.
def test_registration_page
get :register
title = assigns(:title)
assert_equal “Register”, title
assert_response :success
assert_template “register”
#Test the form and all its tags.
assert_tag "form",
:attributes => { :action => "/user/register",
:method => "post"}
assert_tag "input",
:attributes => { :name => "user[screen_name]",
:type => "text",
:size => User::SCREEN_NAME_SIZE,
:maxlength => User::SCREEN_NAME_MAX_LENGTH}
assert_tag "input",
:attributes => { :name => "user[email]",
:type => "text",
:size => User::EMAIL_SIZE,
:maxlength => User::EMAIL_MAX_LENGTH}
assert_tag "input",
:attributes => { :name => "user[password]",
:type => "password",
:size => User::PASSWORD_SIZE,
:maxlength => User::PASSWORD_MAX_LENGTH}
assert_tag "input",
:attributes => { :type => "submit",
:value => "Register!"}
end
# Test a valid registration.
def test_registration_success
post :register, :user => { :screen_name => "new_screen_name",
:email => "[email protected]",
:password =>
“long_enough_password”}
#Test user assignment.
user = assigns(:user)
assert_not_nil user
#Test new user in database.
new_user =
User.find_by_screen_name_and_password(user.screen_name,
user.password)
assert_equal new_user, user
#Test flash and redirect.
assert_equal “User #{new_user.screen_name} created!”,
flash[:notice]
assert_redirected_to :action => “index”
end
# Test an invalid registration.
def test_registration_failure
post :register, :user => { :screen_name => "aa/noyes",
:email => "anoyes@example,com",
:password => "sun"}
assert_response :success
assert_template "register"
#Test display of error messages.
assert_tag "div", :attributes => { :id => "errorExplanation",
:class => "errorExplanation"}
#Assert that each form field has at least one error displayed.
assert_tag "li", :content => /Screen name/
assert_tag "li", :content => /Email/
assert_tag "li", :content => /Password/
#Test to see that the input fields are being wrapped with the
correct div.
error_div = { :tag => “div”, :attributes => { :class =>
“fieldWithErrors”}}
assert_tag "input",
:attributes => { :name => "user[screen_name]",
:value => "aa/noyes"},
:parent => error_div
assert_tag "input",
:attributes => { :name => "user[email]",
:value => "anoyes@example,com"},
:parent => error_div
assert_tag "input",
:attributes => { :name => "user[password]",
:value => "sun"},
:parent => error_div
end
end
and my application.html
<%= @title %> <%= stylesheet_link_tag "site" %> <div id="nav">
<%= nav_link "Home", "site" %> |
<%= nav_link "About Us", "site", "about" %> |
<%= nav_link "Help", "site", "help" %> |
<%= nav_link "Register", "user", "register" %>
</div>
<div id="content">
<% if flash[:notice] -%>
<div id="notice"><%= flash[:notice] %></div>
<% end -%>
<%= yield %>
</div>
<% if ENV['RAILS_ENV'] == "development" %>
<%= debug(params) %>
<% end %>
</div>
and finally session_store:
Be sure to restart your server when you modify this file.
Your secret key for verifying cookie session data integrity.
If you change this key, all old sessions will become invalid!
Make sure the secret is at least 30 characters and all random,
no regular words or you’ll be exposed to dictionary attacks.
ActionController::Base.session = {
:key => ‘_New_Rails_session’,
:secret =>
‘e642035263866262234f2e4fb8a4ce21a1d0e87f453337a6ea7f425186bed13f341dbdf4e0dba12f44b9449bb0903dc3462bde451a0686638cc74fc2d9c7d728’
}
Use the database for sessions instead of the cookie-based default,
which shouldn’t be used to store highly confidential information
(create the session table with “rake db:sessions:create”)
#ActionController::Base.session_store = :active_record_store
I believe the error occured when I ran the db:session:create. However i
deleted the file created and undid my changes to the above 4 files to no
avail.