Delos Chang
Delos Chang

Reputation: 1853

Rails with Devise, works fine on localhost, fails on Heroku

In my Heroku logs:

Processing by UsersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"YsNr73owFsrgM4HX5QDq304ot4gBhGBx1SlOkq+hAxg=", "user"=>{"housing_type"=>"Sublets / Shares", "area_id"=>"1", "subarea_id"=>"", "rent_min"=>"", "rent_max"=>"", "bedroom_min"=>"0", "cat"=>"0", "dog"=>"0", "pic"=>"0", "email"=>"[email protected]"}, "commit"=>"Start your Free Trial: 10 leads"}

app/controllers/users_controller.rb:16:in `create'
Completed 500 Internal Server Error in 6ms
NameError (undefined local variable or method `confirmed_at' for #<User:0x000000048a57b0>):
     app/models/user.rb:81:in `password_required?'

So it fails at line 16 in #create which is the @user.save part:

@user = User.new(params[:user])
if @user.save

And password_required method is declared for Devise in the user.rb file:

  def password_required?
    super if confirmed?
  end

I have already run rake db:migrate and check the migration status to make sure that it has completed on Heroku. I have also run

 heroku run rails console
 irb(main):012:0> User
 => User(id: integer, email: string, trial_count_left: integer, created_at: datetime, updated_at: datetime, rent_min: integer, rent_max: integer, bedroom_min: integer, cat: boolean, dog: boolean, pic: boolean, housing_type: string, subarea_id: integer, area_id: integer, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, confirmation_token: string, confirmed_at: datetime, confirmation_sent_at: datetime, unconfirmed_email: string)

which has confirmed_at

Finally, I've also run through

 heroku run rails console
 irb(main):012:0> User.new( < manual params here >).save

And everything works fine through the interpreter.

What could be going wrong? I'd rather not reset the entire database as it is a production database.

Thanks

Upvotes: 1

Views: 405

Answers (1)

Delos Chang
Delos Chang

Reputation: 1853

For some reason, "heroku restart" did the trick. I'm not sure what was happening in the background, technically speaking but I'm glad it's working now. I will look up Heroku documentations to see if I can pinpoint the underlying technical reason for this.

Upvotes: 2

Related Questions