I am using Rails 3.1.3 on a windows machine, which seems to be generating completely wrong syntax. However, when I run the server, everything seems fine. This is really weird. But, when the same code, a friend of mine runs it(on a Mac), it gives him a load of syntax errors.
This code was a result of generating a scaffold. However, the generator works fine on a Mac.
cities_controller.rb:9: syntax error, unexpected ':', expecting '}'
format.json { render json: @cities }
instead of
cities_controller.rb:9: syntax error, unexpected ':', expecting '}'
format.json { render :json => @cities }
This is really a strange behavior. I don’t know how to fix this.
The
{ render json: @cities }variant is a Ruby 1.9 syntax and it will generate it like that if you are running Ruby 1.9. If your friend upgrades his Ruby to 1.9 (or better, uses rvm to switch versions on the fly) it should work, and if you downgrade to 1.8 your generators will start using the older, more compatible syntax.