Hi everyone I need help with this method:
I have a method that loops trough two models' data and compare them; if a match is found, I want to set the nih_pub match attribute to true then return all nih_pub that have match as false.
it woks well if I use the commented if statement if nih.pubyear == "2003" and nih.pmid == "12538806", but it is not working with the looping.
below is the method i am using:
def compare
nih_pub = NihPublication.where(user: current_user).all
pubmed_pub = Publication.where(user: current_user).all
nih_pub.each{ |nih|
pubmed_pub.each {|pubmed|
if nih.pubyear == pubmed.publication_year and nih.pmid == pubmed.pubmed_id
# if nih.pubyear == "2003" and nih.pmid == "12538806"
nih.match = true
nih.save!
end
}
}
@missing = nih_pub.where(match: false)
end
Thank for your help
if(and the commentedifworked correctly) OR are you having a problem with exiting the loop?returnstatement inifcondition, so it return from loop and gives you@missingas output.nih.match = true nih.save!. if i use the commented if statement, everything works.if nih.pubyear == "#{pubmed.publication_year}" and nih.pmid == "#{pubmed.pubmed_id}" #if nih.pubyear == "2003" and nih.pmid == "12538806" nih.match = true nih.save! end