水豚帖子请求问题
因此,我正在构建一个涉及在页面上提交表单的集成。但是由于某种原因数据库连接在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保设置
,因为 Capybara 测试通过单独的数据库连接。
make sure to set
since Capybara tests goes through a separate database connection.
实际上,共享连接黑客存在问题。例如,如果您使用 gem mysql2,您将开始看到一些错误,例如:
请改用此。该书由迈克·佩勒姆 (Mike Perham) 撰写,全部归功于他。
您还需要安装 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:
Please use this instead. It was written by Mike Perham, all credits to him.
You'll need to install gem
connection_pool
too.This will spare you from many headaches.