通过 VirtualBox 访问开发 Rails 应用程序时出现会话错误
我正在 Ubuntu 10.10 上开发 Rails 3 应用程序,需要检查 IE7 和 IE8 上的 CSS 和 Javascript,因此我使用 VirtualBox 和 Microsoft 提供。我已经安装了映像并且运行良好 - 我可以使用 IE7 和 IE8 访问互联网并正常使用网站。
我还可以通过在每个浏览器中访问 10.0.2.2:3000 来访问我的开发 Rails 应用程序(在 Ubuntu 上运行)(不知道为什么它可以工作,而 localhost 不能,但是哦,好吧)。页面上不需要用户登录的任何 GET 都会按照我的预期呈现。
问题在于会话 - 据我所知,IE7 和 IE8 都完全忽略了与开发应用程序的会话。每当我提交登录表单时,我都会收到 InvalidAuthenticityToken 错误,果然,在 Rails 的错误页面中,会话和参数中的值不匹配。我什至设置了一条特殊的路线来自动以随机用户身份登录访问者,但它不起作用。我刚刚在其中一台虚拟 PC 中下载并安装了 Firefox,它遇到了与 IE 相同的问题。
Ubuntu 中的 Chrome/Firefox 一切正常,所以它似乎不是 Rails,显然也不是 IE。我想 VirtualBox 缺少一些东西,但在今天之前我对虚拟化的经验为零,所以我什至不知道如何开始对其进行故障排除。
有什么建议吗?
I'm developing a Rails 3 app on Ubuntu 10.10 and need to check the CSS and Javascript on IE7 and IE8, so I'm using VirtualBox and the images that Microsoft provides. I've gotten the images installed and running well - I can use IE7 and IE8 to access the internet and use sites just fine.
I can also access my development Rails app (running on Ubuntu) by visiting 10.0.2.2:3000 in each browser (not sure why that works and localhost doesn't, but oh well). Any GET on a page that doesn't require the user to be logged in renders as I'd expect it to.
What's wrong are the sessions - as near as I can tell, both IE7 and IE8 are both just completely ignoring sessions with the development app. Whenever I submit the login form I get an InvalidAuthenticityToken error, and sure enough, in Rails' error page, the values in the session and params don't match. I even set up a special route to automatically log in the visitor as a random user, but it doesn't work. I just downloaded and installed Firefox in one of the virtual PCs and it's having the same problem as the IEs are.
Everything works perfectly in Chrome/Firefox in Ubuntu, so it doesn't seem to be Rails, and apparently it's not IE. I suppose there's something I'm missing with VirtualBox, but I have zero experience with virtualization before today, so I don't even know how to begin troubleshooting it.
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
弄清楚了:cookie没有被设置,因为我是通过ip地址访问应用程序的(Rails的
:domain => :all
cookie存储选项显然不涵盖这种可能性)。我在 WinXP 的主机文件中将 lvh.me 指向 10.0.2.2,一切正常。Figured it out: The cookie wasn't being set because I was visiting the app through the ip address (Rails'
:domain => :all
option for the cookie store apparently doesn't cover that eventuality). I pointed lvh.me to 10.0.2.2 in the hosts file in WinXP, and everything works great.我刚刚在 IE8 上遇到了类似的问题,会话 cookie 被关闭。在我通过以下方式打开会话 cookie 后,我的 Rails 应用程序登录正常:
I just had a similar problem on IE8, session cookies were turned off. My Rails app login worked after I turned session cookies to on via: