2014-12-05 46 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