gpt4 book ai didi

ruby-on-rails - 使用 ruby​​ on rails 为 haml 创建一个助手或其他东西

转载 作者:数据小太阳 更新时间:2023-10-29 06:29:06 25 4
gpt4 key购买 nike

我在我的 Rails 应用程序中使用 haml,我想知道如何以最简单的方式将此 haml 代码插入到 html 文件中:

<div clas="holder">
<div class=top"></div>
<div class="content">
Content into the div goes here
</div>
<div class="bottom"></div>
</div>

我想像这样在我的 haml 文档中使用它:

%html
%head
%body
Maybee some content here.
%content_box #I want to get the code i wrote inserted here
Content that goes in the content_box like news or stuff
%body

有更简单的方法吗?


我收到这个错误:

**unexpected $end, expecting kEND**

使用此代码:

# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def content_box(&block)
open :div, :class => "holder" do # haml helper
open :div, :class => "top"
open :div, :class => "content" do
block.call
open :div, :class => "bottom"
end
end
end

最佳答案

你也可以使用 haml_tag

def content_box
haml_tag :div, :class => "holder" do
haml_tag :div, :class => "top"
haml_tag :div, :class => "content" do
yield
haml_tag :div, :class => "bottom"
end
end

在火腿里

%html
%head
%body
Maybee some content here.
= content_box do
Content that goes in the content_box like news or stuff

关于ruby-on-rails - 使用 ruby​​ on rails 为 haml 创建一个助手或其他东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2523668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com