5

i'm new in the Hanami World. I'have write 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 title method on the template. The html result is:

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

Why the second link overwrite the first? Where is my error?

Thanks for any replies.

NickGnd
  • 5,107
  • 1
  • 20
  • 26
DeepCode
  • 358
  • 2
  • 9

3 Answers3

4

it's the expected behaviour for the current version of hanami/helpers (v0.3.0).

As jodosha wrote on the issue linked above:

After a deeper looking at this issue, it isn't a bug. link_to doesn't work like the other HTML builder methods. That means you can avoid to concat tags.

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

So it's not your fault, but I think the documentation is out of sync, it already shows the new version.

Hope it helps! Bye.

NickGnd
  • 5,107
  • 1
  • 20
  • 26
4

Thanks, i have edit 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
DeepCode
  • 358
  • 2
  • 9
1

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

Luca Guidi
  • 1,201
  • 10
  • 10