Search code examples
htmlcssruby-on-railslink-to

Complex a tag to link_to


A designer gave me the following code snippet:

      <a href="register_learner.html">
        <div class="service-block service-block-sea service-or">
          <div class="service-bg"></div>
          <i class="icon-custom icon-color-light rounded-x fa fa-user-plus"></i>
          <h2 class="heading-md">Register a Learner</h2>
        </div>
      </a>

which I am suppose to make into a single link_to. Is this possible in Rails and if so a hint would be appreciated.

Or maybe am I seeing it wrong? I tried to put the divs out and then put the link_to 'Register Learner', new learner_path in the middle of them but it was not working.


Solution

  • in rails you could do this like

     <%= link_to "register_learner" do %>
        <div class="service-block service-block-sea service-or">
          <div class="service-bg"></div>
          <i class="icon-custom icon-color-light rounded-x fa fa-user-plus"></i>
          <h2 class="heading-md">Register a Learner</h2>
        </div>
      <% end %>
    

    http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

    EDIT - as an aside, putting divs inside a tags used to be frowned upon but is now acceptable practise, as long as there are no interactive elements inside the contents. eg, don't put another link inside.