0

I'm trying to get this menu to work when my site is in mobile. The menu drops down when you tap the screen but because its a link it reloads the page making the menu only appear for a few short seconds. If I remove the "link_to" tag the menu doesn't work at all, so my question is how do i get this menu to open without using the "link_to" tag and without using JavaScript? is this even possible?

Here is the code

        <div id="menu">
            <nav id ="nav" role="navigation">
                <ul>
                    <li>
                        <div class="section group">
                            <div class="col span_1_of_2">
                                <p><%= link_to "Menu v", root_url %></p>
                            </div>
                        </div>
                        <ul>
                            <%= link_to "Home", root_url %>
                            <% @category = Category.all %>
                            <% @category.each do |category| %>
                            <% if category.show_in_header? %>
                            <li><%= link_to "#{category.name}", content_url(category), :controller => 'categories' %></li>
                            <% end %>
                            <% end %>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>

Any help is very much appreciated.

Joe Lloyd
  • 19,471
  • 7
  • 53
  • 81
  • 1
    possible duplicate of [Rails: using link\_to to make a link without href](http://stackoverflow.com/questions/12081156/rails-using-link-to-to-make-a-link-without-href) – Slicedpan Oct 18 '13 at 12:20
  • yes your correct, as I have solved my issue from that question. I was unable to find that question before it was linked.but this is a bit more specific to drop-down menus. should I delete this, or post the solution that I found? – Joe Lloyd Oct 18 '13 at 12:45
  • 1
    I made a demo a while back how to use CSS to open/close a dropdown on click, without Javascript. [Fiddle](http://jsfiddle.net/umDB6/1/). Does that help? – Mr Lister Oct 18 '13 at 13:36
  • thanks, I managed to solve this but this will be a great future reference. – Joe Lloyd Oct 18 '13 at 14:15

1 Answers1

0

by replacing the line

<p><%= link_to "Menu v", root_url %></p>

with

<%= content_tag("a","Menu") %>

I was able to get the menu to open without reloading the page. Making it perfect for use with drop-down menus .

Joe Lloyd
  • 19,471
  • 7
  • 53
  • 81