【发布时间】:2020-01-16 08:47:26
【问题描述】:
我有一个用户必须填写一个字段而不登录。该字段是一个 email_field。 数据库有两个字段:用户电子邮件和 user_id,user_id 是从 webhook 接收的,因此我需要在从 webhook 接收信息后更新数据库中的字段。
这是我的控制器,用于在我的数据库中的用户电子邮件中插入数据:
class EmailsController < ApplicationController
def index
redirect_to root_path
end
def new
@email = Email.new
end
def create
@email = Email.create(email_params)
respond_to do |format|
if@email.persisted?
format.html {redirect_to invoice_index_path, notice: 'Email created '}
else
format.html{render :new}
end
end
end
private
def email_params
params.require(:email).permit(:email, :id_user)
end
end
我的控制器从那里收到 webhook:
class InvoiceController < ApplicationController
def webhooks
render status: 200
user = Email.last
#id_user that I need to fill in my database
puts user.user_id.inspect
#id_user receive from the webhook
id_user = params.dig('connection', 'id_user')
if user.user_id == nil
#POST the id_user in my database
end
end
这是我的问题,如何使用 id_user 从 user.user_id 更新文件?
【问题讨论】:
标签: ruby-on-rails ruby database controller updates