Haml到Erb手动转换

时间:2013-07-02 02:49:22

标签: ruby-on-rails ruby-on-rails-3 haml erb

大家好我有关于如何将以下内容转换为Erb版本模板的问题。 以下是我在Haml的代码:

%li.public.radio{"data-aspect_id" => "public", :class => ("selected" if publisher_public)}

%li.divider.all_aspects.radio{:style => "padding-bottom: 5px; border-bottom: 1px solid #ddd;", "data-aspect_id" => "all_aspects", :class => ("selected" if (!publisher_public && all_aspects_selected?(selected_aspects)))}

我在Erb中的解决方案如下,但似乎运作不正常

<li class="public radio" data-aspect_id="public" class = "#{ 'selected' if publisher_public}">
</li>

<li class="all_aspects divider radio" style="padding-bottom: 5px; border-bottom: 1px solid #ddd;" data-aspect_id="all_aspects" class = "#{ 'selected' if (!publisher_public && all_aspects_selected?(selected_aspects))}"></li>

1 个答案:

答案 0 :(得分:3)

您可能只需要HTML中的一个class属性,#{...}不会在ERB中进行字符串插值(除非它当然位于Ruby块中)。你可能想要更像这样的东西:

<li class="public radio <%= 'selected' if publisher_public %>" data-aspect_id="public">

与其他<li>类似。