In my Rails app I recently tried to use a partial named _next.html.erb
which simply contains a link to the next record:
在我的Rails应用程序中,我最近尝试使用名为_next.html.erb的部分,它只包含指向下一条记录的链接:
<%= link_to_neighbor('next', @company) %>
I then tried to render that partial in my show
and edit
views:
然后我尝试在我的节目中渲染部分并编辑视图:
<%= render 'companies/actions/next' %>
However, that kept giving me an error which I was unable to track down:
但是,这一直给我一个我无法追查的错误:
/app/views/companies/actions/_next.html.erb:1: syntax error, unexpected '=', expecting keyword_end ..._buffer = @output_buffer;next = local_assigns[:next];;@outpu...
What really struck me was the fact that there was in fact no syntax error in the partial. The syntax is absolutely fine.
让我感到震惊的是事实上,部分中没有语法错误。语法绝对没问题。
I wasn't able to get this partial working until I renamed it from _next.html.erb
to _nnnext.html.erb
.
在将其从_next.html.erb重命名为_nnnext.html.erb之前,我无法进行此部分工作。
So I guess next is some kind of reserved word in Rails or Ruby?
所以我猜接下来是Rails或Ruby中的某种保留字?
According to this list it's not, though!
根据这个清单,它不是,但是!
Any ideas?
有任何想法吗?
1 个解决方案
#1
3
next
is a Ruby keyword. Add all such keywords to the list of things you shouldn't name partials in Rails.
next是Ruby关键字。将所有这些关键字添加到不应在Rails中命名为partials的事项列表中。
Because of RoR's wonderful "configuration by convention", all partials get a local variable named after the partial, containing its payload. So to run your partial, Rails evaluated next = local_assigns[:next]
But the next
on the left looks like a keyword, so >kaboom!<
由于RoR的精彩“按惯例配置”,所有部分都获得一个以partial为名的局部变量,包含其有效负载。所以要运行你的部分,Rails评估next = local_assigns [:next]但是左边的下一个看起来像一个关键字,所以> kaboom!<
#1
3
next
is a Ruby keyword. Add all such keywords to the list of things you shouldn't name partials in Rails.
next是Ruby关键字。将所有这些关键字添加到不应在Rails中命名为partials的事项列表中。
Because of RoR's wonderful "configuration by convention", all partials get a local variable named after the partial, containing its payload. So to run your partial, Rails evaluated next = local_assigns[:next]
But the next
on the left looks like a keyword, so >kaboom!<
由于RoR的精彩“按惯例配置”,所有部分都获得一个以partial为名的局部变量,包含其有效负载。所以要运行你的部分,Rails评估next = local_assigns [:next]但是左边的下一个看起来像一个关键字,所以> kaboom!<