2

好的,这变得非常令人沮丧,一个接一个的问题。我将我的应用程序推送到 heroku,当我访问 url 时,我得到了我的登录屏幕(我应该这样做)。但是当我实际尝试登录时,它会给我“无效的用户名/密码”警告消息。但是,在我的本地主机上一切正常。我假设应用程序与我的数据库通信存在问题。我已经运行了“heroku run rake db:migrate”,但没有运气。

在我的本地主机上,我使用的是标准 sqlite3 数据库,但是当我将它推送到 heroku 时,我必须在我的 gem 文件中包含 gem 'pg' 以避免错误。当我将它保留为 gem sqlite3 时,我收到一条错误消息,说它找不到 sqlite3.h 文件或类似的东西。

我可以看到我的数据库位于 postgres.heroku.com 上。我还通过 heroku 支持的推荐安装了这个 gem

宝石'activerecord-postgresql-适配器'

当我尝试输入登录信息时,这里有一些来自 heroku 的日志。任何帮助是极大的赞赏。

←[36m2013-04-04T14:31:15+00:00 app[web.1]:←[0m Started POST "/session" for 74.143.68.203 at 2013-04-04 14:31:15 +0000
←[36m2013-04-04T14:31:15+00:00 app[web.1]:←[0m Processing by SessionsController#create as HTML
←[36m2013-04-04T14:31:15+00:00 app[web.1]:←[0m   Parameters: {"utf8"=>"???", "authenticity_token"=>"rQ1i9DRCV3qju2+RSBwp/9XYW8+6RiLfKfGZFNEcbT8=", "email"=>"admin@ciagent.com", "password"=>"[FILTERED]", "commit"=>"Login"}
←[36m2013-04-04T14:31:15+00:00 app[web.1]:←[0m   Rendered sessions/new.html.erb within layouts/application (0.9ms)
←[36m2013-04-04T14:31:15+00:00 app[web.1]:←[0m Completed 200 OK in 4ms (Views: 2.2ms | ActiveRecord: 1.2ms)
←[33m2013-04-04T14:31:16+00:00 heroku[router]:←[0m at=info method=GET path=/favicon.ico host=boiling-reef-2060.herokuapp.com fwd="74.143.68.203" dyno=web.1 connect=2ms service=7ms status=304 bytes=0
←[33m2013-04-04T14:31:15+00:00 heroku[router]:←[0m at=info method=POST path=/session host=boiling-reef-2060.herokuapp.com fwd="74.143.68.203" dyno=web.1 connect=1ms service=12ms status=200 bytes=1721

我只是不明白为什么当我的应用程序在本地主机上使用相同的用户名/密码时我可以登录,但是当应用程序在 heroku 上时它无法识别登录信息。

附加编辑_ __ _ __ _ __ _ ____

我为我的本地应用程序打开了控制台,并在寻找用户时发现了我所期望的:

$ rails c
Loading development environment (Rails 3.2.13)
irb(main):001:0> user=User.find(1)
  ←[1m←[36mUser Load (5.0ms)←[0m  ←[1mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1←[0m  [["id", 1]]
=> #<User id: 1, email: "admin@ciagent.com", hashed_password: "dc009272b087019fb2b20b691dc827dca1424a1a", created_at: "2010-10-29 19:43:00", updated_at: "2011-01-12 20:07:09", admin: "yes", logo: nil>

当我在heroku上打开控制台时寻找这个时,这是我收到的错误。我会继续寻找修复,但也许你们会看到一个明显的危险信号。

Connecting to database specified by DATABASE_URL
Loading production environment (Rails 3.2.13)
irb(main):001:0> user=User.find(1)
user=User.find(1)
User Load (39.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 1]]
ActiveRecord::RecordNotFound: Couldn't find User with id=1
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:343:in `find_one'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:314:in `find_with_ids'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:107:in `find'
    from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/querying.rb:5:in `find' from (irb):1
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
4

1 回答 1

3

When you run the app on your local computer (a.k.a. development) it is using a local sqlite database. When you run it on heroku (a.k.a. production), it uses a cloud-based postgres database. This is necessary so that you can make changes and develop the app on your local computer, without having to worry about breaking the live production database. Database settings are in config/database.yml.

If you've added the username / password to db/seeds or via a migration, you can reasonably expect the same logins to work in development and production. Presumably, this is what you did before, when you say this worked. Either that, or you had both production and development pointing to the same database (NOT recommended).

Because it's not working here, I'm guessing you added the logins via the console, or via the site itself. You can either run heroku run rails console to open a console on the production server, and add the logins. Or you can add them via a migration, then run the same migration in production so that they're added there as well.

于 2013-04-04T15:45:49.880 回答