Rails - Why is OR not working here? -
i want loop through params , exclude params, used loop:
params.each |key, value| html += "#{key}: #{value}</br>" if key !='authenticity_token' && key != 'utf8' end now, works && when tried replace || :
html += "#{key}: #{value}</br>" if key !='authenticity_token' || key != 'utf8' it didn't work. makes more sense work or because loops through each key, value pair , if key a_token or key, should skip it. there can't both on same line. think don't quite understand how rails processes loops here , why && condition works, please explain me? thanks.
key !='authenticity_token' && key != 'utf8' this return true when key neither authenticity_token nor utf8
whereas
key !='authenticity_token' || key != 'utf8' this return true every key including authenticity_token, utf8 because
for utf8 key key !='authenticity_token' true
abd authenticity_token key key !='utf8' true
if want use || condition use following
!(key =='authenticity_token' || key == 'utf8')
Comments
Post a Comment