Wednesday, 7 August 2013

Rails - Why is OR not working here?

Rails - Why is OR not working here?

I want to loop through the params and exclude certain params, so I used
this loop:
params.each do |key, value|
html += "#{key}: #{value}</br>" if key !='authenticity_token' && key !=
'utf8'
end
Now, this works with && but when I tried to replace it with || :
html += "#{key}: #{value}</br>" if key !='authenticity_token' || key !=
'utf8'
it didn't work. It makes more sense for it to work with OR because it
loops through each key, value pair and if the key IS a_token OR key, then
it should skip it. There can't be BOTH on the same line. I think I don't
quite understand how Rails processes loops here and why the && condition
works, could someone please explain it to me? Thanks.

No comments:

Post a Comment