Hanami link_to helper displays only the last element

I am new to the hanami world. I wrote this code:

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 

I call the title method in the template. Html result:

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

Why is the second link overwriting the first? Where is my mistake?

Thanks for any answers.

+5
source share
3 answers

this is the expected behavior for the current version of hanami/helpers (v0.3.0).

As Yodosha wrote on the issue related above:

After a deeper study of this problem, this is not a mistake. link_to does not work like other HTML building methods. This means that you can avoid concat tags.

The next version (v0.4.0) will allow concat link_to , see PR .

So this is not your fault, but I think that the documentation is not synchronized, it is already showing a new version .

Hope this helps! Bye

+4
source

Thanks, I edited my code:

 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 
+4
source

Now you can combine the two link_to with #+ . See this example: https://github.com/hanami/helpers/pull/52/files#diff-6a0d85bea58ea52c21a97cee6e67cad0R579

+1
source

All Articles