Rails: Touch user column when saving separate db model -



Rails: Touch user column when saving separate db model -

what i'd simple. like:

# == schema info # # table name: tags # # id :integer not null, primary key # tagname :string(255) # user_id :integer class tag < activerecord::base belongs_to :user # when tag gets saved, update right user column on_save_do ->{ user.find(user_id).current_tag = user.find(user_id).current_tag || id } end # == schema info # # table name: users # # id :integer not null, primary key # current_tag :integer class user < activerecord::base has_many :tags, autosave: true, dependent: :destroy end

so need create sure first time tag saved user saves current tag id users current_tag column tag_id.

class tag < activerecord::base belongs_to :user after_save :update_user_tag private def update_user_tag user.current_tag = id user.save if user.changed? end end

ruby-on-rails model

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -