【问题标题】:Can't create admin user on Heroku无法在 Heroku 上创建管理员用户
【发布时间】:2012-06-27 20:53:34
【问题描述】:

我是 Rails 新手,我已经完成了 Lynda.com 上 Kevin Skoglund 的 Ruby on Rails 3 基础培训课程。通过课程,您设置了一个简单的 cms,我做到了。它不包括 Git 或部署,但我已将我的简单 cms 推送到 github (https://github.com/nick5a1/Simple_CMS) 并部署到 Heroku (http://nkarrasch.herokuapp.com/)。

为了部署到 Heroku,我按照 Heroku 设置指南 (https://devcenter.heroku.com/articles/rails3) 将我的数据库从 MySQL 切换到 PostgreSQL。按照指示,我在 Gemfile 中将 gen'mysql2' 更改为 gen'sqlite3' 并在推送之前运行 bundle install 。然后我跑了heroku run rake db:migrate

我遇到了 2 个问题。当我尝试登录 (http://nkarrasch.herokuapp.com/access) 时,我收到一条错误消息“我们很抱歉,但出了点问题”。相反,我应该收到一条包含无效用户名/密码组合的 Flash 消息。这就是我在本地机器上的测试环境中得到的结果。

其次,当我登录 Heroku 控制台以创建和创建管理员用户时,当我尝试保存该用户时,我收到以下错误:

irb(main):004:0> user.save
   (1.2ms)  BEGIN
  AdminUser Exists (1.9ms)  SELECT 1 AS one FROM "admin_users" WHERE "admin_users"."username" = 'Nick5a1' LIMIT 1
   (1.7ms)  ROLLBACK
=> false

任何有关如何排除故障的建议将不胜感激:)。

非常感谢, 尼克

编辑:这是我的 Heroku 日志:

2012-06-27T20:36:44+00:00 heroku[slugc]: Slug compilation started
2012-06-27T20:37:34+00:00 heroku[api]: Add shared-database:5mb add-on by *
2012-06-27T20:37:34+00:00 heroku[api]: Release v2 created by *
2012-06-27T20:37:34+00:00 heroku[api]: Add RAILS_ENV, LANG, PATH, RACK_ENV, GEM_PATH config by *
2012-06-27T20:37:34+00:00 heroku[api]: Release v3 created by *
2012-06-27T20:37:34+00:00 heroku[api]: Release v4 created by *
2012-06-27T20:37:34+00:00 heroku[api]: Deploy 1d82839 by *
2012-06-27T20:37:35+00:00 heroku[slugc]: Slug compilation finished
2012-06-27T20:37:36+00:00 heroku[web.1]: Starting process with command `bundle exec rails server -p 45450`
2012-06-27T20:37:40+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2012-06-27T20:37:40+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2012-06-27T20:37:40+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2012-06-27T20:37:44+00:00 app[web.1]: => Rails 3.2.6 application starting in production on http://0.0.0.0:45450
2012-06-27T20:37:44+00:00 app[web.1]: => Call with -d to detach
2012-06-27T20:37:44+00:00 app[web.1]: => Booting WEBrick
2012-06-27T20:37:44+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2012-06-27T20:37:44+00:00 app[web.1]: => Ctrl-C to shutdown server
2012-06-27T20:37:44+00:00 app[web.1]: [2012-06-27 20:37:44] INFO  WEBrick 1.3.1
2012-06-27T20:37:44+00:00 app[web.1]: [2012-06-27 20:37:44] INFO  ruby 1.9.2 (2011-07-09) [x86_64-linux]
2012-06-27T20:37:44+00:00 app[web.1]: [2012-06-27 20:37:44] INFO  WEBrick::HTTPServer#start: pid=2 port=45450
2012-06-27T20:37:45+00:00 heroku[web.1]: State changed from starting to up
2012-06-27T20:39:44+00:00 heroku[run.1]: Awaiting client
2012-06-27T20:39:44+00:00 heroku[run.1]: Starting process with command `bundle exec rake db:migrate`
2012-06-27T20:39:44+00:00 heroku[run.1]: State changed from starting to up
2012-06-27T20:39:51+00:00 heroku[run.1]: Process exited with status 0
2012-06-27T20:39:51+00:00 heroku[run.1]: State changed from up to complete
2012-06-27T20:41:05+00:00 heroku[run.1]: Awaiting client
2012-06-27T20:41:05+00:00 heroku[run.1]: Starting process with command `bundle exec rails console`
2012-06-27T20:41:05+00:00 heroku[run.1]: State changed from starting to up
2012-06-27T20:46:09+00:00 heroku[run.1]: Process exited with status 0
2012-06-27T20:46:09+00:00 heroku[run.1]: State changed from up to complete

【问题讨论】:

  • 确保在控制台中运行 heroku logs 以查看访问应用程序时收到的错误报告。通常会有足够的细节来指出问题所在。
  • @John 是对的,请提供heroku logs。还要确保你有heroku run rake db:migrate...
  • 谢谢约翰,我已经添加了我的日志。他们似乎没有什么明显的东西?
  • 嗨,Gabriel,我一部署就运行迁移。我重新运行了它们并重新启动了 heroku 服务器,仍然出现相同的 2 个错误。
  • 我已经回答了一个可能的问题,但是您需要在错误之后显示heroku logs....

标签: ruby-on-rails ruby-on-rails-3 heroku


【解决方案1】:

您正在声明两个不同的数据库...尝试从您的 Gemfile 中删除这两行:

gem 'pg'
gem 'mysql2'

并添加以下内容:

group :production do
  gem 'pg'
  gem 'thin'
end

group :development, :test do
  gem 'mysql2'
end

通过这种方式,您可以定义一个用于开发的数据库 (mysql) 和另一个用于生产的数据库 (pg)。

修改gemfile后:

git add .
git commit -m "gemfile updated"
git push
git push heroku master
heroku run rake db:migrate

编辑 - 查看您的routes.rb 我意识到您正在使用match ':controller(/:action(/:id))(.:format)',这将使您可以通过get 请求执行所有操作。但是,我从未使用过它,我认为您的路线可能有问题。

刚刚确定它指向access/attempt_login,能否请您包含以下生成的路由:

rake routes

【讨论】:

  • 谢谢 - 这对不同的开发和生产数据库有意义。不幸的是,在完成上述操作后,我仍然遇到同样的错误。我也在github上做了更新。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-12
  • 2015-11-08
  • 2021-10-15
  • 1970-01-01
相关资源
最近更新 更多