2014-12-05 68 views
0

在Heroku上部署我的rails应用程序后,我遇到了问题。我的应用基本上是一个在线出租车预订平台。我使用Devise来验证用户。我在dev env的SQLite数据库的Users表中有几个用户。因此,在开发环境中,当我尝试使用这些用户中的任何一个登录到我的应用程序时,它完美地工作。但是,当我在Heroku上部署相同,并尝试使用相同的用户凭据登录时,它会向我显示“无效的电子邮件或密码”错误。在Heroku上设计问题

我查了Heroku的日志,能不明白的地方,我错了。请帮忙!

2014-12-05T03:43:18.023059+00:00 app[web.1]: Processing by Devise::SessionsController#new as HTML 
2014-12-05T03:43:18.017343+00:00 app[web.1]: Started GET "https://stackoverflow.com/users/sign_in" for 114.79.138.136 at 2014-12-05 03:43:18 +0000 
2014-12-05T03:43:18.031662+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/devise-3.4.1/app/views/devise/shared/_links.html.erb (0.4ms) 
2014-12-05T03:43:18.031791+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/devise-3.4.1/app/views/devise/sessions/new.html.erb within layouts/application (6.7ms) 
2014-12-05T03:43:18.033007+00:00 app[web.1]: Completed 200 OK in 10ms (Views: 8.3ms | ActiveRecord: 0.0ms) 
2014-12-05T03:43:18.395813+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=www.taxibol.in request_id=e7c11827-dbf9-4b6b-a208-e6c9c3b0cca2 fwd="114.79.138.136" dyno=web.1 connect=1ms 
service=6ms status=304 bytes=133 
2014-12-05T03:43:46.219043+00:00 app[web.1]: Started POST "https://stackoverflow.com/users/sign_in" for 114.79.138.136 at 2014-12-05 03:43:46 +0000 
2014-12-05T03:43:46.226183+00:00 app[web.1]: Processing by Devise::SessionsController#new as HTML 
2014-12-05T03:43:46.226214+00:00 app[web.1]: Parameters: {"utf8"=>"???", "authenticity_token"=>"+EssZfe0ztWQvwNXt0u7/j8ntpBIDdM/l/DusVTXRZI=", "user"=>{"email"=>"[email protected]", "password"=>"[ 
FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"} 
2014-12-05T03:43:46.331970+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/devise-3.4.1/app/views/devise/shared/_links.html.erb (0.4ms) 
2014-12-05T03:43:46.332041+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/gems/devise-3.4.1/app/views/devise/sessions/new.html.erb within layouts/application (3.2ms) 
2014-12-05T03:43:46.332936+00:00 app[web.1]: Completed 200 OK in 107ms (Views: 4.5ms | ActiveRecord: 0.0ms) 
2014-12-05T03:43:46.221273+00:00 app[web.1]: Processing by Devise::SessionsController#create as HTML 
2014-12-05T03:43:46.221311+00:00 app[web.1]: Parameters: {"utf8"=>"???", "authenticity_token"=>"+EssZfe0ztWQvwNXt0u7/j8ntpBIDdM/l/DusVTXRZI=", "user"=>{"email"=>"[email protected]", "password"=>"[ 
FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"} 
2014-12-05T03:43:46.224795+00:00 app[web.1]: Completed 401 Unauthorized in 3ms 
+0

确保你已经跑了所有的迁移和你在Heroku的数据库相同的用户名和密码..从Heroku的控制台 – Dave 2014-12-05 04:15:36

回答

3

我不相信本地开发SQLite数据库中的数据将被导入到Heroku的生产数据库中。

当您部署的网站,你会得到上它具有使应用程序的功能运行迁移一个空数据库,但没有数据被填充,除非你创建种子数据(稍后更多)。

您可以通过heroku的命令行工具(https://devcenter.heroku.com/articles/getting-started-with-rails4#console)使用rails控制台手动创建这些用户,也可以在生产中注册为新用户,而不是通过控制台为管理员授予访问权限。

你可以做最后的方法是用一个管理员用户播种您的数据库和存储配置变量的用户名/密码。基本上你用管理员用户设置种子(http://edgeguides.rubyonrails.org/active_record_migrations.html#migrations-and-seed-data)并通过配置变量(https://devcenter.heroku.com/articles/config-vars)设置用户名/密码。你想使用配置变量,因为把用户名和密码放入种子文件是不安全的。

我从来没有这个具体问题,但我以前处理类似的,我认为这会为你工作。

--Corey

+0

我登录到通过Heroku的铁轨控制台检查,但我无法访问任何的控制器。对于例如Operators.all给出了未初始化的常量错误。我如何访问控制器和数据库表? – 2014-12-05 09:22:58

+0

你是否在heroku上运行迁移? – Corey 2014-12-05 13:27:27

+0

冉迁移,现在Operator.all运行,但它返回一个空数组,即使在开发ENV,Operator.all返回保存在数据库:(。我在哪里卡住了? – 2014-12-05 13:40:09