水豚帖子请求问题

发布于 2025-01-01 05:59:25 字数 411 浏览 2 评论 0原文

因此,我正在构建一个涉及在页面上提交表单的集成。但是由于某种原因数据库连接在post请求期间被破坏了?或者服务器没有访问同一个数据库?

发生的情况是我得到一个社区页面,但是当我在该页面上提交表单时,处理该帖子的控制器不知道该社区。

我已经尝试关闭 Protection_from_forgery 了。连接似乎是相同的(根据 AR:Base.connection)。

我使用的是集成 capybara + rspec 的共享连接池方法。

(ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection)

我正在使用 Rails 3.0.11、rspec 2.6.4、capybara (1.0.0) 和 capybara-webkit (0.8.0)。

So I'm building an integration that involves submitting a form on a page. But for some reason the database connection is broken during the post request? Or the server isn't accessing the same database?

What's happening is I get a page for a Community, but then when I submit the form on that page controller handling the post has no idea about that Community.

I've tried turning off protection_from_forgery already. The connections seem to be same (according to AR:Base.connection).

I'm using the shared connection pool method of integrating capybara + rspec.

(ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection)

I'm using Rails 3.0.11, rspec 2.6.4, capybara (1.0.0), and capybara-webkit (0.8.0).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦萦几度 2025-01-08 05:59:25

确保设置

  RSpec.configure do |config|
    config.use_transactional_fixtures = false
  end

,因为 Capybara 测试通过单独的数据库连接。

make sure to set

  RSpec.configure do |config|
    config.use_transactional_fixtures = false
  end

since Capybara tests goes through a separate database connection.

扛刀软妹 2025-01-08 05:59:25

实际上,共享连接黑客存在问题。例如,如果您使用 gem mysql2,您将开始看到一些错误,例如:

Mysql2::Error This connection is still waiting for a result

请改用此。该书由迈克·佩勒姆 (Mike Perham) 撰写,全部归功于他。

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
  end
end

ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

您还需要安装 gem connection_pool
这将使您免于许多头痛。

Actually there are issues with the shared connection hack. If you use the gem mysql2, for example, you'll start seeing some errors like:

Mysql2::Error This connection is still waiting for a result

Please use this instead. It was written by Mike Perham, all credits to him.

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
  end
end

ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

You'll need to install gem connection_pool too.
This will spare you from many headaches.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文