简体   繁体   English

生产模式下的Rails问题,mysql数据库

[英]Rails problem in production mode, mysql database

App is running smoothly in development mode, but deploying it onto a managed server brings up the public/500.html page ("We're sorry, but something went wrong") , seemingly when content queries the mysql database. App在开发模式下运行平稳,但是将其部署到托管服务器上会显示public / 500.html页面(“很抱歉,出现了问题”) ,似乎是在内容查询mysql数据库时。 Putting up static content works, puzzlingly dynamic content only works locally in dev. 放置静态内容是可行的,令人费解的动态内容只能在dev中本地运行。

rake db:migrate went properly, I've manually inserted a test entry into the mysql database. rake db:migrate运行正常,我已将测试条目手动插入mysql数据库。

Yet requesting the view results in 500 and the log gives 但是请求查看结果为500,日志给出

ActionView::Template::Error (NULL pointer given):
    10:  ...
    11:    <% @projects.each do |project| %>
    12:  ...        

Server runs MySQL 5.1.54, Rails has mysql gem installed. 服务器运行MySQL 5.1.54,Rails安装了mysql gem。 Any hints appreciated! 任何提示表示赞赏!

edit: 编辑:

So I just started 所以我才开始

rails c production

on the remote server and created an entry in my "Client" model: 在远程服务器上,并在“客户端”模型中创建了一个条目:

irb(main):003:0> c = Client.new => #<Client id: nil, name: nil, permalink: nil, created_at: nil, updated_at: nil> irb(main):004:0> c.name = "realclient" => "realclient" irb(main):005:0> c => #<Client id: nil, name: "realclient", permalink: nil, created_at: nil, updated_at: nil> irb(main):006:0> c.save => true

While all fields except for name are displayed empty in irb, the actual DB on the server show all repective fields okay: 尽管名称中除name之外的所有字段都显示为空,但服务器上的实际DB可以正常显示所有相应的字段:

2 realclient realclient 2011-04-22 13:59:12 2011-04-22 13:59:12 (id, name, permalink, created, updated) 2 realclient realclient 2011-04-22 13:59:12 2011-04-22 13:59:12 (ID,名称,永久链接,创建,更新)

So bottom line: Active Record cannot receive values correctly from the DB that are actually there? 因此,最重要的是:Active Record无法从数据库中正确接收实际存在的值?

When you ran rake db:migrate you probably did not have a RAILS_ENV set and so were still running in development environment. 当您运行rake db:migrate您可能没有设置RAILS_ENV ,因此仍在开发环境中运行。 Try running: 尝试运行:

RAILS_ENV=production rake db:migrate

See if you get an error then, and if so you can re-run it with the --trace option for more detail. 查看是否收到错误,如果可以,请使用--trace选项重新运行以获取更多详细信息。

You probably need to debug this issue on your config/database.yml - there'll be something missing or misconfigured in the production section (or maybe you haven't created the DB or something, I'm not familiar with that specific error message). 您可能需要在config/database.yml上调试此问题- 生产部分会丢失或配置错误(或者您可能尚未创建数据库或其他东西,我不熟悉该特定错误消息)。

** Solved ** ** 解决 **

My hosting provider only allows use of their pre-installed mysql 2.7 gem. 我的托管服务提供商仅允许使用其预装的mysql 2.7 gem。 Any manual loading of a mysql gem in Gemfile results in Active Record errors – even loading an own 2.7 version on top. 在Gemfile中手动加载mysql gem都会导致Active Record错误-甚至是在顶部加载自己的2.7版本。 Sticking to the default gem on the managed server works. 坚持使用受管服务器上的默认gem即可。

Setting up a new database individually on the server could probably enable use of custom database gems. 在服务器上单独设置一个新数据库可能可以启用自定义数据库gem。 So while this was a very specific problem, maybe the answer helps somebody else working with rails on a managed server. 因此,尽管这是一个非常具体的问题,但是也许答案可以帮助其他人在托管服务器上使用Rails。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM