1

I added an accordion for an attachment within index.html.erb where I have two tabs named 'users' and 'attachments'.

I also have resource routes defined for both users and attachments.

navbar links

<li><%= link_to "Users", users_path %></li>
<li><%= link_to "Attachments", attachments_path %></li>

When I refresh the page from within the attachments tab and refresh the page I can see the accordion, but when I open the attachment tab with a link_to, I can't see the accordion.

How can I always see the accordion when I am in /attachments route

Edit

attachment.js

$(document).ready(function() {
   $(".accordion").accordion( { collapsible: true } );
});

index.html.erb (just necessary part)

<div class="accordion">
    <% Here some condition with each do |a| %>
        <h3><%= a %></h3> 
        <div>
            <% Here some condition with each do |b|  %>             
                <p><%= b %></p> 
            <% end %>
        </div> 
    <% end %>
</div>
Ramazan Zor
  • 209
  • 1
  • 14
  • 1
    is it possible that you share more of the layout and javascript involved? Without it it would be very hard for you to get help here... – The Fabio Aug 24 '15 at 15:05
  • of course I can but like I said the problem is that accordion only works when I refresh the page from within the attachments tab. I didn't add the code because I think it works even if it only works for like I said – Ramazan Zor Aug 24 '15 at 17:11
  • 2
    Try `$(document).on('ready page:load', function() {...});` – Vucko Aug 24 '15 at 17:23
  • Thank you Vucko, the problem has been solved – Ramazan Zor Aug 24 '15 at 17:33
  • Vucko, please write this as an answer so that i can choose as best answer – Ramazan Zor Aug 24 '15 at 18:58
  • possible duplicate of [Rails 4: how to use $(document).ready() with turbo-links](http://stackoverflow.com/questions/18770517/rails-4-how-to-use-document-ready-with-turbo-links) – Vucko Aug 24 '15 at 20:28

0 Answers0