Ruby 中括号的间距 [英] Spacing around parentheses in Ruby
问题描述
我最近在使路径正常工作时遇到了一些问题.结果证明解决方案很简单,但我遇到了一个意想不到的问题,使我无法解决它.包含在 erb 模板中的以下行非常有效:
I've recently had some problems getting a path working properly. The solution turned out to be simple but I had an unexpected problem that stopped me getting to it. The following line, included in an erb template, works perfectly:
<%= button_to "Confirm delivery", delivery_confirm_path( @delivery ) %>
这个没有:
<%= button_to "Confirm delivery", delivery_confirm_path ( @delivery ) %>
在这种情况下,似乎不允许在左括号之前使用空格.我得到的错误是这样的:
It seems spacing before the opening parenthesis is not allowed in this case. The error I get is this:
/app/views/deliveries/_delivery_buttons.html.erb:22: syntax error,
unexpected tLPAREN_ARG, expecting keyword_do or '{' or '('
...ivery", delivery_confirm_path ( @delivery ) );@output_buffer...
... ^
谁能解释为什么会导致错误?
Can anybody explain why this causes an error?
有关信息,这是 Ruby 1.9.2 和 Rails 3.0.9,在 Windows 7 64 位
for info, this is Ruby 1.9.2 and Rails 3.0.9, on Windows 7 64-bit
推荐答案
任何在参数列表括号前加空格的人都会得到他们应得的,我说!
Anyone that puts a space before a parameter-list parentheses gets what they deserve, I say!
问题在于它正在关闭第二个示例中对 button_to
的调用(括号前的空格),并且不知道接下来要做什么.
The problem is that it's closing out the call to button_to
in the second example (space before the parentheses) and doesn't know what to do next.
这篇关于Ruby 中括号的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!