2016-05-30 24 views
5

我是Hanami世界的新人。 I'have寫這樣的代碼:Hanami link_to helper只呈現最後一個元素

module Web::Views::Home 
    class Index 
    include Web::View 
    include Hanami::Helpers::HtmlHelper 

    def title 
     html.header do 
     h1 'Test search engine', id: 'title' 
     hr 
     div(id: 'test') do 
      link_to('Home', "/", class: 'mnu_orizontal') 
      link_to('About', "/", class: 'mnu_orizontal') 
     end 
     end 
    end 
    end 
end 

我呼籲模板title方法。 HTML結果是:

<header> 
    <h1 id="title">Test search engine</h1> 
    <hr> 
    <div id="test"> 
     <a class="mnu_orizontal" href="/">About</a> 
    </div> 
</header> 

爲什麼第二個鏈接覆蓋第一?我的錯誤在哪裏?

感謝您的回覆。

回答

4

這是當前版本hanami/helpers(v0.3.0)的expected behaviour

由於jodosha上面鏈接的問題寫道:

後更深的看這個問題,這是不是一個錯誤。 link_to不能像其他HTML構建器方法一樣工作。這意味着你可以避免使用標籤。

下一個版本(V0.4.0)將允許Concat的link_to,看到這個PR

所以這不是你的錯,但我認爲documentation是不同步的,它已經顯示new version

希望它有幫助!再見。

4

謝謝,我有我的編輯代碼:

module Web::Views::Home 
    class Index 
    include Web::View 
    include Hanami::Helpers::HtmlHelper 

    def title 
     html.header do 
     h1 'Global search engine (GSearch)', id: 'title' 
     hr 
     div(id: 'test') do 
      ul do 
      li (link_to('Home', "/", class: 'mnu_orizontal')) 
      li (link_to('About', "/", class: 'mnu_orizontal')) 
      end 
     end 
     end 
    end 
    end 
end 
相關問題