Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4.2 syntax error, unexpected ':', expecting =>

I have two computers that I mainly use to develop my Rails application. While working on Computer 1, I added some bootstrap elements to some inputs. For example:

= f.select :transport_from_state, options_for_select(state_populator, @invoice_ambulance.transport_from_state), { include_blank: true}, { class: 'chosen-select', 'data-placeholder': 'State' } 

I added the 'data-placeholder': 'State' and used the 'newer' syntax instead of the old :data-placeholder' => 'State' which works fine. The page works with no errors on Computer 1.

I pulled down on computer 2, and now I am getting an error for every instance of 'data-placeholder'. Here is my error:

syntax error, unexpected ':', expecting =>
...en-select', 'data-placeholder': 'State' }

I can replace it with the old syntax and it works fine. However, I shouldn't have to switch 100 instances of this to a deprecated syntax. I have since bundle installed, bundle updated, and rebuilt the db with no luck.

Computer 1 (works)

ruby 2.2.0p0

Rails 4.2.0

Computer 2 (doesnt work)

ruby 2.2.0preview1

Rails 4.2.0

like image 568
kevinweaver Avatar asked Dec 19 '22 03:12

kevinweaver


2 Answers

You need to upgrade Computer 2 to the real Ruby 2.2.0 rather than this beta-ish "preview" version you have. Using quoted symbols with the JavaScript-style trailing colon syntax:

{ 'some string': value }

wasn't valid before Ruby 2.2, the 2.2.0preview1 version you have on Computer 2 apparently doesn't support it.


BTW, there is no old and new syntax, there is an alternate JavaScript-style notation that can be use when the keys in a Hash-literal are some symbols. Whoever told you that the hashrocket is deprecated is, at best, confused.

like image 50
mu is too short Avatar answered Dec 30 '22 16:12

mu is too short


The "newer" syntax is only for symbols.

{hello: 'world'} is equivalent to {:hello => 'world'} but if your key is a string then you still have to use the "hash rocket" syntax: {'hello' => 'world'}

http://ruby-doc.org/core-2.2.0/Hash.html

like image 29
AndrewH Avatar answered Dec 30 '22 18:12

AndrewH