0

I am facing issues after deploying my rails app on Heroku. My app essentially is an online cab booking platform. I have used Devise to authenticate users. I have several users in the Users table in the SQLite DB in the dev env. As such, in the dev env, when I try to log into my app using any of these users, it works perfectly. However, when I deploy the same on Heroku, and try to login using the same user credentials, it shows me "Invalid email or password" error.

I checked the Heroku logs, can't understand where I am going wrong. Please help!

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 "/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 "/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"=>"raju.s@merucabs.com", "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"=>"raju.s@merucabs.com", "password"=>"[
FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
2014-12-05T03:43:46.224795+00:00 app[web.1]: Completed 401 Unauthorized in 3ms  
Rahul Poddar
  • 343
  • 1
  • 4
  • 12
  • make sure you have ran all migrations and you have same username and password in heroku database.. check from heroku console – Dave Dec 05 '14 at 04:15

1 Answers1

3

I don't believe the data in the local dev SQLite DB will be imported into your production database on Heroku.

When you deploy that site, you're going to get an empty database which has migrations run on it so the app functions, but no data is populated unless you create seed data (more on that later).

You can either manually create those users using rails console via heroku's command line tools (https://devcenter.heroku.com/articles/getting-started-with-rails4#console) or sign up as a new user on production than give yourself admin access via the console.

The last way you can do it is by seeding your database with an admin user and storing the username / password in configuration variables. Basically you setup a seed (http://edgeguides.rubyonrails.org/active_record_migrations.html#migrations-and-seed-data) with an admin user and setup the username / password via config vars (https://devcenter.heroku.com/articles/config-vars). You want to use config vars because putting usernames and passwords in a seed file is insecure.

I've never had this specific issue, but I've deal with similar ones before, and I think this will work for you.

--Corey

Corey
  • 159
  • 8
  • I logged into the rails console via Heroku, but I am unable to access any of the controllers. For e.g. Operators.all gives uninitialized constant error. How do I access the controllers and DB tables? – Rahul Poddar Dec 05 '14 at 09:22
  • Did you run migrations on heroku? – Corey Dec 05 '14 at 13:27
  • Ran migrations, now Operator.all runs but this returns an empty array, even though in dev env, Operator.all returns all the operators that are saved in the DB :(. Where am I stuck now? – Rahul Poddar Dec 05 '14 at 13:40
  • That makes sense because no data in dev is automatically imported to your production database. You must make those operators again on production. Try doing Operator.new to create new records in the production database. – Corey Dec 05 '14 at 13:42
  • okay...so is there no way to automatically import data in dev to prod? – Rahul Poddar Dec 05 '14 at 13:48
  • Maybe this will help http://stackoverflow.com/questions/62201/how-and-whether-to-populate-rails-application-with-initial-data – Corey Dec 05 '14 at 14:01