所以我的模式下有此代码
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string
# surname :string
# user_id :integer
# count :integer default(0)
# was :boolean default(FALSE)
# qrcode :string
# created_at :datetime not null
# updated_at :datetime not null
#
class User < ApplicationRecord
validates :name, presence: true
validates :surname, presence: true
validates :user_id, presence: true
after_create :generate_qr
private
def generate_qr
ian = User.find(id)
ian.update_attribute(:qrcode, "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + user_id.to_s)
# update_attribute(:qrcode, "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + user_id.to_s)
end
end
它可以正常工作并在我的本地主机上生成二维码。但是当我在heroku上部署时,heroku日志中会出现此错误。
2018-06-30T14:23:37.200657+00:00 app[web.1]: I, [2018-06-30T14:23:37.200507 #4] INFO -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] Parameters: {"utf8"=>"✓", "authenticity_token"=>"mBkhE7alyyKGtS4v+tnW2Vpg6c1z0kwQfbnftqTWdSukTpre29vkqVmeuVoGR7NJzs0EoxiQv0rS+WzJ4hUSOw==", "user"=>{"name"=>"fdsfds", "surname"=>"fdsfdsfds", "user_id"=>"53454"}, "commit"=>"Create User"}
2018-06-30T14:23:37.204598+00:00 app[web.1]: D, [2018-06-30T14:23:37.204527 #4] DEBUG -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] (1.1ms) BEGIN
2018-06-30T14:23:37.207575+00:00 app[web.1]: D, [2018-06-30T14:23:37.207496 #4] DEBUG -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] User Create (1.5ms) INSERT INTO "users" ("name", "surname", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["name", "fdsfds"], ["surname", "fdsfdsfds"], ["user_id", 53454], ["created_at", "2018-06-30 14:23:37.204956"], ["updated_at", "2018-06-30 14:23:37.204956"]]
2018-06-30T14:23:37.214137+00:00 app[web.1]: D, [2018-06-30T14:23:37.214060 #4] DEBUG -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] User Load (1.3ms)
SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 7], ["LIMIT", 1]]
2018-06-30T14:23:37.215729+00:00 app[web.1]: D, [2018-06-30T14:23:37.215664 #4] DEBUG -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] (1.1ms) ROLLBACK
2018-06-30T14:23:37.224955+00:00 app[web.1]: I, [2018-06-30T14:23:37.224881 #4] INFO -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] Completed 500 Internal Server Error in 24ms (ActiveRecord: 6.1ms)
2018-06-30T14:23:37.225904+00:00 app[web.1]: F, [2018-06-30T14:23:37.225838 #4] FATAL -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a]
2018-06-30T14:23:37.226043+00:00 app[web.1]: F, [2018-06-30T14:23:37.225990 #4] FATAL -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] NoMethodError (undefined method `qrcode=' for #<User:0x00000004fd1d68>):
2018-06-30T14:23:37.226091+00:00 app[web.1]: F, [2018-06-30T14:23:37.226046 #4] FATAL -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a]
2018-06-30T14:23:37.226146+00:00 app[web.1]: F, [2018-06-30T14:23:37.226103 #4] FATAL -- : [56b953ac-5a43-4b25-980d-f2bc5c53883a] app/models/user.rb:25:in `generate_qr'
请有人帮忙。我不知道哪里是错误。在我的本地主机上工作正常。