ruby-on-railsruby-on-rails-4public-activity

Render_activity in a Bootstrap dropdown menu isn't working properly


So I am doing this in a Bootstrap dropdown menu in a partial in my main layout:

      <% @unread_act.each do |notification| %>
        <li>
    <%= render_activity notification %>
        </li>
      <% end %>

@unread_act is declared in my application_controller.rb like so:

  @unread_act = Notification.where(recipient_id: current_user).includes(:trackable => [:user, :node]).order("created_at desc")      

Then in my views/public_activity/comment/_create.html.erb, I have this:

added a comment to which has since been removed

The issue is that in the dropdown menu, it doesn't display this info. It literally just displays what would be the equivalent of:

activity.trackable.node.name

No idea where it is getting that information, but that's what it is doing.

Any ideas on how I can customize this dropdown menu for my needs?

Also as an aside, I have no idea why the dropdown passes notification to render_activity, but the gem still wants activity.trackable. I tried notification.trackable but that didn't work.


Solution

  • This is my Dropdown menu, based on Bootstrap:

    <div class="notifications bootstrap-styles">
        <div class="dropdown">
        <a data-toggle="dropdown" class="dropdown-toggle" href="#"><%= @unread_act.size %></a>
            <ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dLabel">
              <% @unread_act.each do |notification| %>
                <li>
                                <%= render_activity notification %>
                            </li>
              <% end %>
    
             <li><%= link_to "Mark all as read", mark_all_read_activities_path, method: :put %></li>
          </ul>
        </div>
    </div>
    

    What was happening is that this Dropdown menu will only display links.

    So it is only the elements within a link_to tag that get shown in the menu.