ruby on rails - ActiveRecord boolean resets to default on update -


i have boolean field has default value of false in joining table of has many through relationship: tags , tag lists.

add_column :taggings, :tag_visible, :boolean, :default => false 

the theory tag list can have many tags (and vice versa) tags visibility can turned off/on per tag list. part of nested resource: document has_one :tag_list

for part working. default value set on creation , updating each instance ajax call.

however when update document includes tag_list token input field resets of tagging's visibility false regardless of previously.

any leads appreciated.

turns out in tags token_input setter inside tag_list model deleting , recreating new record in tagging model instead of updating it.

old code:

self.taggings = tag.ids_from_tokens(tokens, user_id).each_with_index.map {|t,i| tagging.new(:tag_id => t, :tag_colour => tag_colours[i % tag_colours.size]) } 

fix:

self.tag_ids = tag.ids_from_tokens(tokens, user_id) self.taggings.each_with_index {|t,i| t.update_attributes(:tag_colour => tag_colours[i % tag_colours.size]) } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -