我已经制作了一个部分来生成页面的一些布局,并且在部分中有一个空间,我需要在其中插入描述。
描述是来自部分调用者的静态文本,而且相当长。所以我想把它写成一个文本 block 。
这就是我所拥有的:
= render "feature", title: "Planning", text: <<-BLOCK
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
BLOCK
但是当我尝试渲染页面时,我得到:
can't find string "BLOCK" anywhere before EOF
最佳答案
我宁愿使用 yield
并在 content_for
block 中提供内容。
在你的部分:
%p Other content wrapping the block of text
= yield :text_block
%p Other content wrapping the block of text
那么在你看来:
= content_for :text_block do
The content you need to insert goes here ...
关于ruby-on-rails - 将 ruby block 传递给 HAML 中的部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21415570/