Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8296125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:51:54+00:00 2026-06-08T14:51:54+00:00

I have a nav menu with 2 tabs/links in the show.html.erb file, in UsersController.rb

  • 0

I have a nav menu with 2 tabs/links in the show.html.erb file, in UsersController.rb, I would like to use ajax to render different partial for the tabs.

In the show.html.erb I have a div named profile-data where I want to show the content.
So I do something like this:

The link structure:

<li><%= link_to "College friends", college_friends_path, :remote => true %></li>
<li><%= link_to "Highschool friends", highschool_friends_path, :remote => true %></li>

I define the routes:

match "college_friends" => "users#college_friends", :as => "college_friends"
match "highschool_friends" => "users#highschool_friends, :as => "highschool_friends"

And I define in my UserController.rb the necessary methods:

class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
  end

  def college_friends
    respond_to do |format|
      format.js
    end
  end

  def highschool_friends
    respond_to do |format|
      format.js
    end
  end
end

Last thing we have the JS files:

*college_friends.js.erb*

$('#profile-data').html("<%= escape_javascript(render(:partial => 'college_friends')) %>");

*highschool_friends.js.erb*

$('#profile-data').html("<%= escape_javascript(render(:partial => 'highschool_friends')) %>");

The partial code: _college_friends.html.erb

<% groups = @user.friends.group_by(&:college_name) %>
<% sorted_groups = groups.sort_by{|key, values| values.count}.reverse %>
<% sorted_groups.each do |collegename, friends| %>
<% next if collegename.blank? %>
<div class="contentbox">
    <div class="box-header">
        <h3><%= collegename %></h3>
        <div class="meta-info">
            <p><i class="icon-map-marker"></i> Malmö</p>
            <p><i class="icon-user"></i><span class="count"> <%= friends.count %></span> vänner</p>
        </div>
    </div>
    <ul class="friends-list">
        <% friends.map do |friend| %>
        <li><%= image_tag(friend.image) %>
            <% end %> 
        </ul> 
    </div>
<% end %>

So I solve this problem but checking the source in and out. And I notice that the js files was not loaded in the app.

So I changed this:

<%= javascript_include_tag :defaults %>

To this:

<%= javascript_include_tag "application" %>

And it loaded all the necessary js files.

But then I get this error:

ActionView::Template::Error (undefined method `friends' for nil:NilClass):
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:51:55+00:00Added an answer on June 8, 2026 at 2:51 pm

    You are getting

    ActionView::Template::Error (undefined method `friends' for nil:NilClass):
    

    Because

    <% groups = @user.friends.group_by(&:college_name) %>
    

    requires @user to be set.

    As Brandon suggested, try

    def college_friends
      @user = User.find(params[:id])
      respond_to do |format|
        format.js
      end
    end
    

    BUT

    To achieve this, you need to change your link routes to include user id, similar to this

    match "college_friends/:id" => "users#college_friends", :as => "college_friends"
    

    and in your links

    <li><%= link_to "College friends", college_friends_path(@user), :remote => true %></li>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a nav menu with 2 tabs/links in the show.html.erb file, in UsersController.rb
I have nav code like this in my HTML file: <div id="center_links"> <ul> <li><a
I have a problem. I would like to use the animate() function to slide
I have this horizontal menu. The menu looks like tabs and are 29px high.
I have a nav menu for which I want to use a lava lamp
I have this nav menu with 2 tabs: <div id=user_menu> <ul class=nav nav-tabs> <li
Ok, very very weird issue here. I have a sub nav menu that links
I have a menu set up this way: <div id='top-navigation'> <ul> <li><a class='top-nav-button-unclicked' href='#'>SUBJECT</a></li>
I have a nav button added by myself. when click it I use: $(#+gridId).setColProp('myColumn',
My goals: I want to have #nav to be divide into menu-left and menu-right,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.