简体   繁体   English

Rails 4.2语法错误,意外':',期待=>

[英]Rails 4.2 syntax error, unexpected ':', expecting =>

I have two computers that I mainly use to develop my Rails application. 我有两台计算机,主要用于开发我的Rails应用程序。 While working on Computer 1, I added some bootstrap elements to some inputs. 在计算机1上工作时,我在一些输入中添加了一些引导元素。 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. 我添加了'data-placeholder': 'State'并使用了'newer'语法而不是旧的:data-placeholder' => 'State' ,它运行正常。 The page works with no errors on Computer 1. 该页面在计算机1上没有错误。

I pulled down on computer 2, and now I am getting an error for every instance of 'data-placeholder' . 我拉下了计算机2,现在我收到了'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. 但是,我不应该将此实例的100个实例切换为不推荐使用的语法。 I have since bundle installed, bundle updated, and rebuilt the db with no luck. 我已经安装了捆绑包,更新了捆绑包,并重建了数据库而没有运气。

Computer 1 (works) 电脑1(工程)

ruby 2.2.0p0 红宝石2.2.0p0

Rails 4.2.0 Rails 4.2.0

Computer 2 (doesnt work) 电脑2(不起作用)

ruby 2.2.0preview1 ruby 2.2.0preview1

Rails 4.2.0 Rails 4.2.0

You need to upgrade Computer 2 to the real Ruby 2.2.0 rather than this beta-ish "preview" version you have. 您需要将计算机2升级到真正的Ruby 2.2.0而不是这个beta-ish“预览”版本。 Using quoted symbols with the JavaScript-style trailing colon syntax: 使用带有JavaScript样式的尾部冒号语法的带引号的符号:

{ '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. 在Ruby 2.2之前无效,你在计算机2上拥有的2.2.0preview1版本显然不支持它。


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. 顺便说一下,没有旧的新的语法,当Hash-literal中的键是某些符号时,可以使用备用的JavaScript样式表示法。 Whoever told you that the hashrocket is deprecated is, at best, confused. 谁告诉你hashrocket被弃用的人充其量是混淆的。

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'} {hello: 'world'}相当于{:hello => 'world'}但是如果你的键是一个字符串,那么你仍然需要使用“hash rocket”语法:{'hello'=>'world'}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM