我使用Ruby on Rails 5.2.3,Mongoid和Devise
我有两个模型,我需要从父模型传递button_color值
user.rb
class User
include Mongoid::Document
field :button_color, type: String, default: '#FFFFFF'
has_many :items, dependent: :destroy
end
item.rb
class Item
include Mongoid::Document
field :button_color, type: String
belongs_to :user, touch: true
end
我需要得到类似的东西
field:button_color,类型:字符串,默认值:current_user.button_color
class Item
belongs_to :user
delegate :button_color, to: :user
end