【问题标题】:How to send email activation link with Heroku and Send Grid?如何使用 Heroku 和 Sendgrid 发送电子邮件激活链接?
【发布时间】:2018-01-17 08:04:39
【问题描述】:

我尝试发送电子邮件激活链接时出现 Heroku 日志错误:

2018-01-17T07:37:09.783615+00:00 应用[web.1]: [f3c128f0-83ad-4879-ae6c-a54b28030290] [1m[35m (0.7ms)[0m [1m[35m开始[0m 2018-01-17T07:37:09.891482+00:00 app[web.1]: [f3c128f0-83ad-4879-ae6c-a54b28030290] 完成 500 内部服务器 188 毫秒内的错误(ActiveRecord:10.7 毫秒) 2018-01-17T07:37:09.892707+00:00 应用 [web.1]: [f3c128f0-83ad-4879-ae6c-a54b28030290]
2018-01-17T07:37:09.871499+00:00 应用 [web.1]: [f3c128f0-83ad-4879-ae6c-a54b28030290] [1m[35m (1.1ms)[0m [1m[31m回滚[0m 2018-01-17T07:37:09.892886+00:00 app[web.1]: [f3c128f0-83ad-4879-ae6c-a54b28030290] NoMethodError(未定义的方法 激活摘要=为# 2018-01-17T07:37:09.892887+00:00 app[web.1]:你的意思是?激活令牌=): 2018-01-17T07:37:09.892920+00:00 应用 [web.1]: [f3c128f0-83ad-4879-ae6c-a54b28030290]
2018-01-17T07:37:09.892966+00:00 app[web.1]: [f3c128f0-83ad-4879-ae6c-a54b28030290] app/models/user.rb:71:in create_activation_digest 2018-01-17T07:37:09.892967+00:00 应用程序 [web.1]: [f3c128f0-83ad-4879-ae6c-a54b28030290] app/controllers/users_controller.rb:23:in `create' 2018-01-17T07:37:09.892966+00:00 heroku[路由器]: at=info method=POST path="/users" host=letsgo228.herokuapp.com request_id=f3c128f0-83ad-4879-ae6c-a54b28030290 fwd="61.6.75.149" dyno=web.1 连接=1ms 服务=194ms 状态=500 字节=1891 协议=https 2018-01-17T07:37:10.572375+00:00 heroku[路由器]: at=info method=GET path="/favicon.ico" host=letsgo228.herokuapp.com request_id=6b2a9847-7844-4ae9-a7df-e1405b86b08f fwd="61.6.75.149" dyno=web.1 连接=0ms 服务=1ms 状态=304 字节=112 协议=https

用户模型

 # Creates and assigns the activation token and digest.
  def create_activation_digest
    self.activation_token  = User.new_token
    self.activation_digest = User.digest(activation_token)
  end
end

user_contrller

def new
    @user = User.new
  end

  def create
    @user = User.new(user_params)
    if @user.save
      @user.send_activation_email
      flash[:info] = "Пожалуйста проверьте свою почту,в течении 1 минуты придет письмо для активации аккаунта"
      redirect_to root_url
    else
      render 'new'
    end
  end

【问题讨论】:

  • 您是否有任何公共存储库可以查看您的模型代码,或者您可以发布您的完整模型

标签: ruby-on-rails ruby git heroku sendgrid


【解决方案1】:

您的用户模型上没有名为activation_digest 的列。 rails g migration add_activation_digest_to_users activation_digest:string:index

【讨论】:

  • 我有这个 def 更改 add_column :users, :activation_digest, :string add_column :users, :activated, :boolean, 默认值:false add_column :users, :activation_at, :datetime end end
  • 你跑heroku run rake db:migrate了吗?
猜你喜欢
  • 1970-01-01
  • 2018-01-05
  • 2016-07-05
  • 2019-05-27
  • 2020-04-20
  • 1970-01-01
  • 1970-01-01
  • 2021-06-19
  • 2014-09-09
相关资源
最近更新 更多