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:
我有两台电脑,主要用于开发Rails应用程序。在处理计算机1时,我在一些输入中添加了一些引导元素。例如:
= 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.
我添加了“data-placeholder”:“State”,并使用了“较新的”语法,而不是使用了“old:data-placeholder”=>“State”,这很好。这个页面在计算机1上没有错误。
I pulled down on computer 2, and now I am getting an error for every instance of 'data-placeholder'
. Here is my error:
我打开计算机2,现在我得到了每个“data-placeholder”实例的错误。这是我的错误:
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.
我可以用旧的语法替换它,它运行得很好。但是,我不需要将100个实例转换为不赞成的语法。从那以后,我就安装了bundle,对其进行了更新,并重新构建了db。
Computer 1 (works)
计算机1(作品)
ruby 2.2.0p0
ruby 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
2 个解决方案
#1
7
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:
您需要将计算机2升级到真正的Ruby 2.2.0版本,而不是您现有的beta“预览”版本。使用引用的符号和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. Whoever told you that the hashrocket is deprecated is, at best, confused.
顺便说一下,这里没有新的语法,有一个备用的javascript风格的符号,可以用在Hash-literal中的键是一些符号的时候。不管谁告诉你hashrocket已经被弃用了,往好了说,他都很困惑。
#2
2
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
#1
7
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:
您需要将计算机2升级到真正的Ruby 2.2.0版本,而不是您现有的beta“预览”版本。使用引用的符号和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. Whoever told you that the hashrocket is deprecated is, at best, confused.
顺便说一下,这里没有新的语法,有一个备用的javascript风格的符号,可以用在Hash-literal中的键是一些符号的时候。不管谁告诉你hashrocket已经被弃用了,往好了说,他都很困惑。
#2
2
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