【问题标题】:Rails 3.1. How to make a menu builder output haml?导轨 3.1。如何使菜单生成器输出haml?
【发布时间】:2012-04-23 13:47:36
【问题描述】:

我一直在关注一个简​​短的tutorial 在我的应用程序上构建一个标签菜单。

这是 Applciation_helper 中的 menu_builder 方法

def menu_builder(page_id)
 tabs = ['events','locations','account']
 content = ""
 tabs.each do |tab|
   content << if page_id == tab
     content_tag('li', content_tag('a', tab, :href => nil ), :class => 'active')
   else
     content_tag('li', content_tag('a', tab, :href => "/#{tab}" ), :class => 'inactive')
   end
 end
 content_tag(:ul, content, :class => 'tabnav')
end

application.html.haml

%nav
  = menu_builder(@page_id)

这是输出的源代码

<nav>
    <ul class="tabnav">&lt;li class=&quot;active&quot;&gt;&lt;a&gt;events&lt;/a&gt;&lt;/li&gt;&lt;li class=&quot;inactive&quot;&gt;&lt;a href=&quot;/locations&quot;&gt;locations&lt;/a&gt;&lt;/li&gt;&lt;li class=&quot;inactive&quot;&gt;&lt;a href=&quot;/account&quot;&gt;account&lt;/a&gt;&lt;/li&gt;</ul>
</nav>

我玩过haml_tag 等,但不知道如何使menu_builder 方法输出正确的语法。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 haml


    【解决方案1】:

    尝试替换:

    content = ""
    

    与:

    content = "".html_safe
    

    【讨论】:

    • 或使用raw 助手:content = raw ""
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 2011-09-01
    • 2012-04-24
    • 2017-03-11
    • 2012-06-14
    相关资源
    最近更新 更多