def replaceranked
oldrankings = Question.where(:rank => [1,2,3,4,5])
# Mocking the creation of a new top 5
newrankings = Question.where(:id => [4,5,6,7,8])
newrankings.each_with_index |a, i|
a.rank = i+
end
oldids = oldrankings.map{|a| a.id}
newids = newrankings.map{|a| a.id}
simlarities = oldids & newids
oldrankings.each_with_index do |a, i|
if !(similarities.includes?(a.id))
newrankings.push(a)
oldrankings.delete_at(i)
end
end
oldrankings.map{|a| a.rank = nil}
updatedtopfive = newrankings | oldrankings
updatedtopfive.map{|a| a.save}
end
SyntaxError: (RIR): 275: erreur de syntaxe, unexpected '}' (RIR): 280: erreur de syntaxe, tIDENTIFIER inattendue, expecting ':' . ..newrankings.push (a) oldrankings.delete_at (i): suivant} ...^ (irb): 280: erreur de syntaxe, inattendue ':', attendez '}' ... h (a) oldrankings .delete_at (i): suivant} ...^ (irb): 284: erreur de syntaxe, inattendu keyword_end, attendez '}' depuis lib/rails/commands/console.rb: 44: dans start' from lib/rails/commands/console.rb:8:in
start ' from lib/rails/comm ands.rb: 23: dans <top (required)>' from script/rails:6:in
require ' de script/rails: 6: dans `'Méthode pour remplacer la vieille classe des questions avec des questions récemment classement
Question Modèle
Id:Integer
Content:String
Rank:Integer #Normally Null unless ranked in which case you'll have a rank of 1 to 5