0

It's a really simple question. Is this:

format.json { render json: @student.errors, status: :unprocessable_entity }

100% equivalent to this:

format.json { render json: @student.errors, status => :unprocessable_entity }

It seems to be, but maybe I'm missing a subtlety? If it is equivalent, why is the colon notation better? I assume there's a reason, as Rails uses the first notation in scaffolds, but those opposing colons bother me.

crowhill
  • 2,398
  • 3
  • 26
  • 55
  • The colon notation was introduced in Ruby 1.9 and looks a lot cleaner. But I don't see arrow notation as being deprecated any time soon or having any advantages in this particular case, so yea I think its more about what you prefer using. – TarunJadhwani Jun 02 '15 at 15:21
  • According to the duplicated answer, there are some differences. The TL;DR version being that `=>` will always work as expected and `:` will not. Also, the `=>` is called a "rocket," which is great. – crowhill Jun 02 '15 at 15:24
  • @crowhill How doesn't it work as expected? The semantics are well-defined. Are you referring to how it expects the value to be a valid symbol? – Dave Newton Jun 02 '15 at 16:18

0 Answers0