How to use mixpanel with twitter bootstrap dropdown menu? - ruby-on-rails

My code looks like this:
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav pull-right">
<% if user_signed_in? %>
<li class="dropdown" id="menu7">
<a class="dropdown-toggle" id="username" data-toggle="dropdown" href="#">
<%= current_user.full_name %>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to('Edit my account', edit_user_registration_path,
:id => 'edit_account') %></li>
<li><%= link_to('Logout', destroy_user_session_path, :method => 'delete',
:id => 'logout_link') %></li>
</ul>
</li>
<% else %>
<li><%= link_to('Login', new_user_session_path, :id => 'login_link') %></li>
<li><%= link_to('Sign up', new_user_registration_path, :id => 'signup_link') %></li>
<% end %>
</ul>
</div>
</div>
And my javascript events are these:
mixpanel.track_links('#username', 'Username clicked')
mixpanel.track_links('#edit_account', 'Edit account link clicked')
mixpanel.track_links('#logout_link', 'Logout link clicked')
I don't know why (i really looks bizarre!) only the event 'Username clicked' is working. Has anyone experienced something similar?

One possibility is that you need to include the link tag in your selector:
mixpanel.track_links('#username a', 'Username clicked')
mixpanel.track_links('#edit_account a', 'Edit account link clicked')
mixpanel.track_links('#logout_link a', 'Logout link clicked')
That's how it's done in the Mixpanel doc.
Another option is you may be going about this the wrong way. Instead of tracking clicks on links, maybe you want to use the ruby API and put your trackers in the controller, as shown in this part of the doc.
Thus, you would do something like this in your Users controller:
def edit
track_event "edits account"
end
And in sessions conroller:
def destroy
track event "logs out"
end

Related

Why doesn't my dropdown menu expand to select the options within?

I'm building a review site using ruby on rails. When I code the drop-down menu, included in the code below, it won't expand.
I know from changing the code that the options are there and work, only the dropdown won't expand.
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<%= link_to "NDLabClub", root_path, class: "navbar-brand" %>
</div>
<ul class="nav navbar-nav">
<li><%= link_to "Sign Up", new_user_registration_path %></li>
<% if user_signed_in? %>
<li><%= link_to "Sign Out", destroy_user_session_path, method: :delete %></li>
<% else %>
<li><%= link_to "log In", new_user_session_path %></li>
<% end %>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
aria-expanded="false">Categories <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<% Category.all.each do |category| %>
<li>
<%= link_to category.breed, dogs_path(category: category.breed), class: "link" %>
</li>
<% end %>
</ul>
</li>
<% if user_signed_in? %>
<li><%= link_to "Add Dog", new_dog_path%></li>
<% end %>
</ul>
</div>
</nav>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>

How to link to another part of another page?

I have the below as my nav, however, the index.html.erb#meetflappy is throwing up an error:
Routing Error
No route matches [GET] "/preorder/index.html.erb"
I'd like it so that when users click meetflappy tab, they are brought to the index page and specifically to the #meetflappy part. Now this works when I'm on the index page and it just links to #meetflappy but when I'm on another page i'm having trouble here. Please advise:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="wrapper-nav">
<div class="navbar-header">
<%= link_to logo, root_path, class: 'brand' %></a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class=""><%= link_to 'Meet Flappy', 'index.html.erb#meetflappy' %></li>
<li class=""><%= link_to 'Details', 'index.html.erb#details' %></li>
<li class=""><%= link_to 'FAQ', faq_path %></li>
<li class=""><%= link_to 'Flappy\'s Story', flappystory_path %></li>
<li class=""><%= link_to 'About Us', about_path %></li>
<li class=""><%= link_to 'Checkout', preorder_checkout_path %></li>
</ul>
</div>
</div>
</nav>
Change this:
<%= link_to 'Meet Flappy', 'index.html.erb#meetflappy' %>
to this:
<%= link_to 'Meet Flappy', root_path(anchor: 'meetflappy') %>

App name in the navbar

I am creating a sample app as a learner. How do I fix the code below to have "One Month Rails" appear on every page of my app, in the left of my navigation bar? Thank you!
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<% link_to "One Month Rails", root_path, class: "brand" %>
<div class="nav-collapse">
<ul class="nav">
<li>
<%= link_to 'Home', root_path %>
</li>
<li>
<%= link_to 'About', about_path %>
</li>
</ul>
<ul class="nav pull-right">
<% if user_signed_in? %>
<li><%= link_to "Edit Profile", edit_user_registration_path %></li>
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
<% else %>
<li><%= link_to "Login", new_user_session_path %></li>
<% end %>
</ul>
</div>
</div>
</div>
This will work for you...
<%= Rails.application.class.parent_name %>
Or more specifically...
<%= link_to Rails.application.class.parent_name, root_path, class: "brand" %>
Don't forget the equals sign in front of the link_to call.

Showing users name on nav bar when logged in using ruby on rails

I want to be able to replace Accounts tab on my navigation bar with the User's name when they logged in. How would i go about doing that. Would i have to use some sort of embedded ruby like <%= #user.name %>
heres the html
enter code here
<header class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", '#' %></li>
<li id="fat-menu" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", user_path(current_user) %></li>
<li><%= link_to "Settings", '#' %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: 'delete' %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
</header>
Try:
<%= current_user.name %>

_header.html.erb account dropdown function does not work

I am following the ruby on rails tutorials from http://ruby.railstutorial.org .
The following is the _header.html.erb code, is the same as the tutorials. but the drop down function of account does not work.
<header class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", users_path %></li>
<li id="fat-menu" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
</header>
Without seeing more of the application it's hard to determine the exact problem, however based on what you have supplied I can suggest the following:
refer to http://twitter.github.com/bootstrap/javascript.html#dropdowns and ensure you are using the right markup nesting (looks like you are)
make sure you have included the javascript files within your application.js file (your manifest file). The docs for bootstrap here: http://twitter.github.com/bootstrap/components.html#navbar say that you need to have the dropdown JS file included to make the dropdown work properly.
Please let me know if any of this helps.

Resources