App model has many association to links model
App Model
class App < ActiveRecord::Base
has_many :links, class_name: "Link"
accepts_nested_attributes_for :links
before_save :update_flags
def update_flags
if self.links.ios_enabled?
self.flags = "-DFLAG"
end
end
end
Link Model
class Link < ActiveRecord::Base
belongs_to :app
end
When the ios_enabled checkbox is selected, the condition which i used in before_save callback returns the old value of "ios_enabled" attribute from the nested model "Links"
Example: old value = false new value = true
it returns the old value(false) when this condition "self.links.ios_enabled?" is used, not the entered value(true).
How to handle this.Kindly help
Aucun commentaire:
Enregistrer un commentaire