我是使用rails_admin进行管理面板。只需更改Image模型中的关联即可。
从这个开始
从这个开始
class Image < ApplicationRecord
belongs_to :user
belongs_to :product
end
转换为:
class Image < ApplicationRecord
has_one :user
has_one :product
end
用户模型是
class User < ApplicationRecord
has_many :images,dependent: :destroy
end
当我尝试从管理面板编辑用户时,遇到了这个错误。但是从其他方面来看,它运行良好。
ActiveRecord::StatementInvalid at /user/72/edit
PG::UndefinedColumn: ERROR: column users.image_id does not exist
LINE 1: SELECT "users".* FROM "users" WHERE "users"."image_id" = $1...
^
: SELECT "users".* FROM "users" WHERE "users"."image_id" = $1 LIMIT $2
has_attached_file:image
,然后你就可以开始了。 - quetzaluzclass Image < ApplicationRecord belongs_to :user belongs_to :product, optional: true end
这对我很有效,感谢你的帮助。 - Tanay Sharma