HAML 块在产量时返回“0”?
我刚刚升级到 Rails3、Ruby 1.9.2 和最新的 HAML gem。 此代码曾经有效:
= allowed? do
= link_to('New', new_video_path)
现在 允许?
产生 0
。
如果我这样做,它就会起作用:
= allowed?{ link_to('New', new_video_path) }
什么给出了?
I just upgraded to Rails3, Ruby 1.9.2 and the latest HAML gem.
This code used to work:
= allowed? do
= link_to('New', new_video_path)
Now allowed?
yields 0
.
It works if I do:
= allowed?{ link_to('New', new_video_path) }
What gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
执行此收益概念以允许正确捕获您想要的任何内容的最简洁方法是:
但是,在您的情况下,为什么不编写另一个辅助方法呢?
并像这样使用它:
The cleanest way to do this yield concept to allow whatever content you'd like to be properly captured is:
In your case, though, why not just write another helper method?
And use it like this:
你为什么首先要回应它的输出?您应该这样做:
一般来说,您永远不想在块中使用输出运算符(
=
)。块中输出的内容不会返回到块中;它直接连接到缓冲区中。使用这样的块可能会产生内容无序的错误。Why are you echoing the output of that in the first place? You should be doing:
In general, you never want to use the output operator (
=
) with a block. Stuff outputted in blocks doesn't get returned to the block; it's concat'd directly into the buffer. Using a block like that is likely to produce errors with content out of order.这花了我一段时间才找到,但这就是你如何做到的:
问题是 haml 将所有内容输出到它自己的特殊缓冲区,然后再将其发送到机架或任何地方。所以你必须让haml先调用该块并对其进行缓冲。
This took me a while to find, but this is how you do it:
The problem is that haml outputs everything to its own special buffer before sending it on to rack or wherever. So you have to let haml call the block first and buffer it.