2

On my home page, there is a link to user's show page

<a id="event_shortcut" href="http://localhost:3000/users/1#event_tab">show events</a>

and in user's show, I used bootstrap tab,

<ul id="user_show_tabs">
    <li >
        <a href="#profile_tab">Profile</a>
    </li>
    <li>
        <a href="#event_tab">Events</a>
    </li>
    <li class="active">
        <a href="#account_tab">Account</a>
    </li>
</ul>

When I click on the link it should go to the user's show page and the event tab should be in foucs. So in js I did like this,

$("#event_shortcut").live("click", function(event){
    event.preventDefault(); 
    window.location = $(this).attr("href"); 
    $('#user_show_tabs a[href="#event_tab"]').tab('show');
});

this js code redirects the user to the show page but the event tab is not set focus. I don't know what I am missing. Help me!

albertedevigo
  • 18,262
  • 6
  • 52
  • 58
  • You can't simply execute javascript from one page in another. Check those questions : **duplicate : http://stackoverflow.com/a/10120221/1478467**, kind of the same : http://stackoverflow.com/q/7862233/1478467 – Sherbrow Aug 31 '12 at 22:44

2 Answers2

2

When you redirect to another page, the tab list is getting refreshed. You either need to put in logic to only have the class="active" on the tab for the current page, or you need to use the tab-content method and have all of the pages load in separate content divs, so the tabs don't actually leave the page they just change which <div> is being displayed.

Check out the Javascript section of Bootstrap to get more info on how to do this. http://twitter.github.com/bootstrap/javascript.html#tabs

Steve Valliere
  • 1,882
  • 12
  • 31
0

in the view(this is haml)

%ul
  li{:class => "#{check_if_active('release')}"
    = link_to "release", part_release_path(@current_organisation, @part)

and in helper

def check_if_active(tab)
  case params[:controller]
  when "parts"
    if ['release'].include?(params[:action])
      tab == "properties" ? "active" : "null"
    end
end
Prasad Surase
  • 6,486
  • 6
  • 39
  • 58