Я обновил до rails 3.1 "пример приложения" из Rails 3 Tutorial.Все прошло гладко, за исключением того, что когда я использую сайт и вошедший в систему пользователь пытается подписаться / отписаться от другого пользователя, я получаю следующее сообщение из журнала:
Started POST "/relationships" for 127.0.0.1 at 2011-09-29 20:06:30 -0400
Processing by RelationshipsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Yn4XSU4RSEjGqpv1H/ZAxTAi/5JREDaBaa5UbPArRAo=", "relationship"=>{"followed_id"=>"7"}, "commit"=>"Follow"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 101 LIMIT 1
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "7"]]
SQL (3.5ms) INSERT INTO "relationships" ("created_at", "followed_id", "follower_id", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Fri, 30 Sep 2011 00:06:30 UTC +00:00], ["followed_id", 7], ["follower_id", 101], ["updated_at", Fri, 30 Sep 2011 00:06:30 UTC +00:00]]
Relationship Load (0.2ms) SELECT "relationships".* FROM "relationships" WHERE "relationships"."follower_id" = 101 AND "relationships"."followed_id" = 7 LIMIT 1
Rendered users/_unfollow.html.erb (3.5ms)
(0.2ms) SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."follower_id" WHERE "relationships"."followed_id" = 7
Rendered relationships/create.js.erb (6.7ms)
Completed 200 OK in 51ms (Views: 12.1ms | ActiveRecord: 4.7ms)
Started POST "/relationships" for 127.0.0.1 at 2011-09-29 20:06:31 -0400
Processing by RelationshipsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Yn4XSU4RSEjGqpv1H/ZAxTAi/5JREDaBaa5UbPArRAo=", "relationship"=>{"followed_id"=>"7"}, "commit"=>"Follow"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 101 LIMIT 1
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "7"]]
SQL (0.6ms) INSERT INTO "relationships" ("created_at", "followed_id", "follower_id", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Fri, 30 Sep 2011 00:06:31 UTC +00:00], ["followed_id", 7], ["follower_id", 101], ["updated_at", Fri, 30 Sep 2011 00:06:31 UTC +00:00]]
SQLite3::ConstraintException: constraint failed: INSERT INTO "relationships" ("created_at", "followed_id", "follower_id", "updated_at") VALUES (?, ?, ?, ?)
Completed 500 Internal Server Error in 35ms
SQLite3::ConstraintException (columns follower_id, followed_id are not unique):
Операция должна работать, так как этоВпервые я создаю эту ассоциацию.После этой ошибки мне нужно перезапустить сервер, чтобы вернуться к моему пользователю, в противном случае сервер продолжает работать.Вот пример:
Rendered /Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms)
Rendered /Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (3.7ms)
[2011-09-29 20:08:12] ERROR SQLite3::Exception: cannot use a closed statement
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:110:in `close'
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:110:in `block in clear_cache!'
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:110:in `each'
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:110:in `clear_cache!'
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activerecord-3.1.0/lib/active_record/connection_adapters/sqlite_adapter.rb:104:in `disconnect!'
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:214:in `block in clear_reloadable_connections!'
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:213:in `each'
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:213:in `clear_reloadable_connections!'
/Users/huguesjoly/.rvm/gems/ruby-1.9.2-p180 rails3tutorial/gems/activesupport-3.1.0/lib/active_support/core_ext/module/synchronization.rb:35:in `block in clear_reloadable_connections_with_synchronization!'
...
Итак, вернувшись к моему пользователю после перезапуска, я вижу, что запись все равно была создана.Но если я пытаюсь удалить это отношение, я получаю следующую ошибку из этого файла журнала:
Started DELETE "/relationships/95" for 127.0.0.1 at 2011-09-29 20:11:59 -0400
Processing by RelationshipsController#destroy as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7YfmrROy4dqviuRakYSyWz2xZLbqIBwfU5McvqBWBrU=", "commit"=>"Unfollow", "id"=>"95"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 101 LIMIT 1
Relationship Load (0.1ms) SELECT "relationships".* FROM "relationships" WHERE "relationships"."id" = ? LIMIT 1 [["id", "95"]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 7 LIMIT 1
Relationship Load (0.1ms) SELECT "relationships".* FROM "relationships" WHERE "relationships"."follower_id" = 101 AND "relationships"."followed_id" = 7 LIMIT 1
SQL (0.3ms) DELETE FROM "relationships" WHERE "relationships"."id" = ? [["id", 95]]
Rendered users/_follow.html.erb (2.0ms)
(0.2ms) SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."follower_id" WHERE "relationships"."followed_id" = 7
Rendered relationships/destroy.js.erb (5.3ms)
Completed 200 OK in 68ms (Views: 32.5ms | ActiveRecord: 1.5ms)
Started DELETE "/relationships/95" for 127.0.0.1 at 2011-09-29 20:11:59 -0400
Processing by RelationshipsController#destroy as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7YfmrROy4dqviuRakYSyWz2xZLbqIBwfU5McvqBWBrU=", "commit"=>"Unfollow", "id"=>"95"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 101 LIMIT 1
Relationship Load (0.1ms) SELECT "relationships".* FROM "relationships" WHERE "relationships"."id" = ? LIMIT 1 [["id", "95"]]
Completed 404 Not Found in 28ms
ActiveRecord::RecordNotFound (Couldn't find Relationship with id=95):
app/controllers/relationships_controller.rb:24:in `destroy'
Опять же, если я возвращаюсь на страницу пользователя, я вижу, что отношение было удалено.Похоже, что исключения создаются без причины.И действительно, если я rspec-тестирую отношения следующий / подписчик, все работает правильно.Кроме того, версия sample_app с использованием rails 3.0 работает отлично.
Возможно ли, что у одного из драгоценных камней есть ошибка в контексте rails 3.1?Вот список моего Gemfile на случай, если он поможет:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'gravatar_image_tag', '1.0.0'
gem 'will_paginate', '3.0.1'
gem 'sqlite3', '1.3.4'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.1"
gem 'uglifier'
end
# Is replacing: gem 'prototype-rails'
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :development do
gem 'rspec-rails', '2.6.1'
gem 'annotate', '2.4.0'
gem 'faker', '1.0.0'
end
group :test do
gem 'rspec-rails', '2.6.1'
gem 'webrat', '0.7.3'
gem 'spork', '0.8.5'
gem 'factory_girl_rails', '1.2.0'
# Pretty printed test output
gem 'turn', :require => false
end
Заранее спасибо,