Getting syntax error, unexpected ':', expecting '=' in Ruby - ruby-on-rails

I am very new to Ruby and trying to run a script ,When I am trying to run a Ruby script like below, I am getting
> ruby test.rb
test.rb:53: syntax error, unexpected ':', expecting ')'
All::Config.new_global_config(domain: domain, realm: realm)
^
test.rb:53: syntax error, unexpected ':', expecting '='
All::Config.new_global_config(domain: domain, realm: realm)
When I see ruby version, it says:
> ruby -version
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
-e:1: undefined local variable or method `rsion' for main:Object (NameError)
Any pointers? Is it because of the version? 1.8.x instead of 1.9 or more?

The {key: 'value'} syntax was added in ruby v1.9. To do this in v1.8, you need to use the {:key => 'value'} syntax (which is still valid in modern ruby, too).
1.8 and 1.9 are both very old versions!!! Neither has been supported for a long time. (1.8 was retired in 2013; 1.9 in 2015.)
The latest version, at the time of writing this, is 2.4.1. Use this if possible.
The oldest supported version of ruby is 2.2.7.

Related

"make rails" giving syntax errors in terminal

Every time I run "make rails" I get syntax errors and warnings within my terminal.
I'm using ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin18.0] because the project I'm working on mandates it, but I can update if needed.
We are currently using a legacy rails site as one of the users in the comments pointed out. This led to the find that we are our project would need to be run on ruby 2.3.0 as SOLR doesn't support the newer versions in our project. Furthermore, running bundle install also helps to resolve dependencies of older projects.
This is what I get when I make rails:
Ahans-MacBook-Pro:app ahansabharwal$ make rails
POSTGRES starting
pg_ctl -D ./db/development.pg -l ./db/development.pg/postgres.log start
waiting for server to start.... done
server started
Connection to localhost port 5432 [tcp/postgresql] succeeded!
SOLR starting
bundle exec rake sunspot:solr:start
/Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2097: warning: else without rescue is useless
/Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2103: warning: else without rescue is useless
/Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2142: warning: else without rescue is useless
rake aborted!
SyntaxError: /Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2093: syntax error, unexpected modifier_if
if separator.value == 'auto'
^
/Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2097: syntax error, unexpected ',', expecting keyword_end
/Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2103: syntax error, unexpected ')', expecting keyword_end
/Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2138: syntax error, unexpected modifier_if
if separator.value == 'auto'
^
/Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2142: syntax error, unexpected ')', expecting keyword_end
/Users/ahansabharwal/.rvm/gems/ruby-2.1.3#project/gems/sass-3.7.2/lib/sass/script/functions.rb:2920: syntax error, unexpected keyword_end, expecting end-of-input
.
. (similar syntax errors)
.
(See full trace by running task with --trace)
make[1]: *** [solr-force-start] Error 1
make: *** [solr] Error 2
Solved this issue by installing ruby 2.3.0, older versions aren't supported by SOLR. (2.6.0 onwards is not currently supported in our project)

ruby encoding error on windows

Wondering if anyone has ever come across the error
Caught Encoding::CompatibilityError at '{"command_id":"cc8bf': incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string) (JSON::ParserError)
I get this the following is called
expect(page.element.text.to_s.force_encoding("UTF-8").match msg).to be_true
As you can see, I have added "to_s.force_encoding("UTF-8")" but i still get the error.
My version of ruby is 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
Running on a mac and the tests pass with no errors.

Cannot generate any migrations for Rails 4.2, Ruby 2.1.4. Syntax error in bin/rails

Whenever I try to create a migration, I get the following error. Does anyone know what could be causing this?
$ rails generate migration NewMigration
/Users/myuser/.rvm/gems/ruby-2.1.4/bin/ruby_executable_hooks:15:in `eval': /Users/myuser/.rvm/gems/ruby-2.1.4/bin/rails:19: syntax error, unexpected '=', expecting keyword_end (SyntaxError) /Users/myuser/.rvm/gems/ruby 2.1.4/bin/rails:23: syntax error, unexpected end-of-input, expecting keyword_end
from /Users/myuser/.rvm/gems/ruby-2.1.4/bin/ruby_executable_hooks:15:in `<main>'
Somehow your bin/rails file got modified. Run gem pristine -a in the same rvm you were using before. This rebuilds / reinstalls all your gem files.

Unable to install SproutCore

I used
rvm 1.8.7 do gem install sproutcore
It was installed successfully, but now on running sproutcore gen project getting_started
it gives me the following errors:
/Users/user/.rvm/gems/ruby-1.8.7-p370/gems/sproutcore-1.8.2.1/vendor/chance/lib/chance/instance/slicing.rb:22: syntax error, unexpected ':', expecting '}'
mtime: file[:mtime],
^
/Users/user/.rvm/gems/ruby-1.8.7-p370/gems/sproutcore-1.8.2.1/vendor/chance/lib/chance/instance/slicing.rb:23: syntax error, unexpected ':', expecting '='
canvas: canvas
^
/Users/user/.rvm/gems/ruby-1.8.7-p370/gems/sproutcore-1.8.2.1/vendor/chance/lib/chance/instance/slicing.rb:234: syntax error, unexpected $end, expecting kEND
I think this is a "known bug" with Ruby 1.8.7 as it's using some syntax that is only available in 1.9.
You should probably try upgrading to Ruby 1.9.2 or 1.9.3 which should fix the issue.
I agree with Topher Fangio, but to add how: this is what I did.
gem update --system

SyntaxError on the welcome to rails screen using Pow

I have just set up a new project which displays all the correct info in the about your applications environment window when on http://localhost:3000/ but when I run it at http://egg.dev/ I get:
SyntaxError: /users/davidhall/work/egg/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end
...sion_store :cookie_store, key: '_egg_session'
^
I'm sure I had this problem earlier, which was due to me using rails 3.1 with ruby 1.8.7, the problem resolved when I used ruby 1.9.2. Now I'm getting when using 1.9.2 too.
Thanks for any help its much appreciated!
The Problem is that, there is a new-style hash argument available in Ruby1.9.2 but unavailable in Ruby1.8.7 which is
key: value # only available in 1.9.2
||
:key => value # available in 1.8.7 and 1.9.2
so, with a less effort, you can just modify the syntax to the one that 1.8.7 recognized.
As you can read in the Pow User's Manual under point 2.3 you have to add a .rvmrc into the root directory of your project with the content rvm 1.9.2.
Then it should work!
I resolved this by deleting the ~/.rvm directory and reinstalling RVM.

Resources