密码重置让我在生产中出现500错误

时间:2015-07-08 17:02:50

标签: ruby-on-rails heroku railstutorial.org

我正在尝试按照Michael Hartl的教程添加密码重置到我的应用程序。在localhost:3000中,当我输入我的电子邮件以发送密码重置时,它表示它可以正常工作(我得到一个闪存[:成功],因为它已经编程完成)。然后当我访问邮件程序预览并重置我的密码时,它可以工作(虽然我实际上并没有收到电子邮件,所以我不知道是否真的创建了reset_digest,因为user_mailer_preview会自动创建一个对于数据库中的第一个用户(我)。

然而,在生产中(在heroku上),当我输入我的电子邮件发送密码重置时,我只得到500错误。这是我的heroku日志:

2015-07-08T16:55:11.773924+00:00 app[web.1]: Started GET "/password_resets/new" for 71.202.16.30 at 2015-07-08 16:55:11 +0000
2015-07-08T16:55:11.855679+00:00 app[web.1]:   Rendered password_resets/new.html.erb within layouts/application (3.5ms)
2015-07-08T16:55:11.862888+00:00 app[web.1]:   Rendered layouts/_nav.html.erb (1.4ms)
2015-07-08T16:55:11.865474+00:00 app[web.1]: Completed 200 OK in 34ms (Views: 19.3ms | ActiveRecord: 0.0ms)
2015-07-08T16:55:11.831107+00:00 app[web.1]: Processing by PasswordResetsController#new as HTML
2015-07-08T16:55:11.860630+00:00 app[web.1]:   Rendered layouts/_head.html.erb (2.7ms)
2015-07-08T16:55:11.864807+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.9ms)
2015-07-08T16:55:11.871089+00:00 heroku[router]: at=info method=GET path="/password_resets/new" host=readlio.herokuapp.com request_id=4fca3717-319b-4d23-9a55-6e7795caa6ef fwd="71.202.16.30" dyno=web.1 connect=2ms service=99ms status=200 bytes=4219
2015-07-08T16:55:15.372791+00:00 app[web.1]: Completed 500 Internal Server Error in 138ms
2015-07-08T16:55:15.230300+00:00 app[web.1]: Started POST "/password_resets" for 71.202.16.30 at 2015-07-08 16:55:15 +0000
2015-07-08T16:55:15.234361+00:00 app[web.1]: Processing by PasswordResetsController#create as HTML
2015-07-08T16:55:15.254529+00:00 app[web.1]:   User Load (1.6ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 LIMIT 1  [["email", "cozymonster29@gmail.com"]]
2015-07-08T16:55:15.234393+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"XoYIZsoFM7aDANpKPO9DlxWDKlRe1OGBrXO1PBGJHVS89AmlU2aKExmGgH9/mUWNwrK3eq9pzMo+AJx384Bt9Q==", "password_reset"=>"[FILTERED]", "commit"=>"Submit"}
2015-07-08T16:55:15.374555+00:00 app[web.1]: 
2015-07-08T16:55:15.374558+00:00 app[web.1]: NoMethodError (undefined method `reset_digest=' for #<User:0x007ff5bbb90f88>):
2015-07-08T16:55:15.374562+00:00 app[web.1]:   app/controllers/password_resets_controller.rb:12:in `create'
2015-07-08T16:55:15.374560+00:00 app[web.1]:   app/models/user.rb:47:in `create_reset_digest'
2015-07-08T16:55:15.374563+00:00 app[web.1]: 
2015-07-08T16:55:15.374564+00:00 app[web.1]: 
2015-07-08T16:55:15.384624+00:00 heroku[router]: at=info method=POST path="/password_resets" host=readlio.herokuapp.com request_id=09d2d771-1119-4fa9-abc8-c47d30e95497 fwd="71.202.16.30" dyno=web.1 connect=0ms service=154ms status=500 bytes=1714
2015-07-08T16:55:15.590920+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=readlio.herokuapp.com request_id=95cb9d84-534a-4d8e-9290-172721301867 fwd="71.202.16.30" dyno=web.1 connect=1ms service=4ms status=200 bytes=188

这是我的控制器的一部分:

def create
    @user = User.find_by(email: params[:password_reset][:email].downcase)
    if @user
      @user.send_password_reset_email
        flash[:info] = "An email was sent to " + @user.email + " with password reset instructions."
        redirect_to login_url
    else
        flash.now[:danger] = "Hmm. We don't recognize that email. Make sure you signed up with this email."
        render 'new'
    end
  end

这是我的用户模型create_reset_digest

的一部分
def create_reset_digest
    self.reset_token = User.new_token
    update_attribute(:reset_digest, User.digest(reset_token))
    update_attribute(:reset_sent_at, Time.zone.now)
  end

  def send_password_reset_email
    UserMailer.password_reset(self).deliver_now
  end

所以它告诉我,没有reset_digest这样的方法,我很困惑,因为我从来没有真正称之为。我在@user.create_reset_digest中致电def create,我认为这是heroku logs正在呼唤的行。我该如何解决这个错误?

1 个答案:

答案 0 :(得分:1)

  

所以它告诉我,没有像reset_digest这样的方法   我很困惑,因为我从来没有真正称呼它。我打电话   def create中的@ user.create_reset_digest,我认为这就是行   heroku日志正在呼唤

没有! create_reset_digestuser.rb中调用reset_digest中的update_attribute(:reset_digest, User.digest(reset_token))实际上 更新 heroku run rake db:migrate 此行File f = new File("Audio/Testing/mbgitr.wav"); try { ProcessBuilder pb = new ProcessBuilder("bash/extractAudio.sh", f.getAbsolutePath()); pb.inheritIO(); pb.start(); }catch(IOException e){ System.out.println("Oh no!"); } System.out.println(new File("Audio/mbgitr.wav").exists());

  

NoMethodError(未定义的方法`reset_digest =&#39; for   用户:0x007ff5bbb90f88

我认为您没有在 heroku 上运行 迁移 。您应该使用以下命令运行迁移。

/home/Ryan/Development/Java/Test/Audio/Testing/mbgitr.wav
mbgitr.wav
/home/Ryan/Development/Java/Test
false
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
[more ffmpeg output]

Process finished with exit code 0

这可以解决您的错误。