我有两个表account和display_colors,如果一个用户更改颜色,则display_colors表具有10个带有颜色代码的默认ID,所有用户的颜色都将更改, 我试图找出是否有一种方法可以为每个用户或我拥有的任何其他选项创建一个不同的表,而无需更改前端的实际逻辑
我尝试使用关联Emirates_to和has_many,其中display_colors有一个account_id列,但每次更新都会对其进行更改
display_color.rb
#TODO: Add for account level
belongs_to :account
def self.update_colors(colors)
import colors, on_duplicate_key_update: { conflict_target: [:id], columns: [:max_range, :color_code] }
end
def self.color_code(conf)
rounded = (conf * 100).round
where("min_range <= ? AND max_range >= ?", rounded, rounded).first.try(:color_code)
end
end
** Account.rb **
class Account < ApplicationRecord
has_many :display_colors
validates_uniqueness_of :name
def self.default
where(name: 'default').first
end
end
屏幕快照显示db表看起来像我有10列,那十列对于用户来说是唯一的,并且在开始时每个帐户都具有默认值