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 8296635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:05:57+00:00 2026-06-08T15:05:57+00:00

So I am trying to setup a view for my friendship model from Amistad,

  • 0

So I am trying to setup a view for my friendship model from Amistad, but I keep getting this error: “undefined method `each’ for nil:NilClass”

This is my friendship.rb model

class Friendship < ActiveRecord::Base
  include Amistad::FriendshipModel

    attr_accessible :user_id, :friend_id
end

This is my friendships_controller.rb

class FriendshipsController < ApplicationController
  before_filter :authenticate_user!

  def index
    @friends = current_user.friends
    @pending_invited_by = current_user.pending_invited_by
    @pending_invited = current_user.pending_invited
  end

  def create
    @Friend = User.find(params[:user_id])
    @friendship_created = current_user.invite(@Friend)
  end

  def approve
    @Friend = User.find(params[:user_id])
    @friendship_approved = current_user.approve(@Friend)
    @friends = current_user.friends
    @pending_invited_by = current_user.pending_invited_by
  end

  def remove
    @Friend = User.find(params[:user_id])
    @friendship = current_user.send(:find_any_friendship_with, @Friend)
    if @friendship
      @friendship.delete
      @removed = true
    end
   end
  end

My user model user.rb

class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
  has_many :cereals, dependent: :destroy

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:login]
  include Amistad::FriendModel

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :login, :avatar, :avatar_cache, :remove_avatar, :firstname, :lastname, :phone, :urlname
  # attr_accessible :title, :body

  attr_accessor :login

  def self.find_first_by_auth_conditions(warden_conditions)
      conditions = warden_conditions.dup
      if login = conditions.delete(:login)
        where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
      else
        where(conditions).first
      end
    end

            def update_with_password(params={})
        current_password = params.delete(:current_password)

        if params[:password].blank?
          params.delete(:password)
          params.delete(:password_confirmation) if params[:password_confirmation].blank?
        end

                result = if params[:password].blank? || valid_password?(current_password) 
          update_attributes(params)
        else
          self.attributes = params
          self.valid?
          self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
          false
        end

        clean_up_passwords
        result
      end
    end

and users_controller.rb

class UsersController < ApplicationController
    def show
      if params[:id].nil? && current_user
        @user = current_user
      else
        @user = User.find(params[:id])
      end
      @cereal = current_user.cereals.build if signed_in?
      @cereals = @user.cereals.paginate(page: params[:page])
  end

  def first_time
      if params[:id].nil? && current_user
        @user = current_user
      else
        @user = User.find(params[:id])
      end
  end

    def edit
        if params[:id].nil? && current_user
            @user = current_user
        else
            @user = User.find(params[:id])
        end
  end

    def profile
        @username = params[:id]
        @title = "User Profile for #{@username}"
        @user = User.find_by_username(@username)
        @users = User.all :conditions => ["id != ?", current_user.id]
  end 

end

Anyone have any idea whats going on? I am still new at rails, and could use some insight.

The View:

.row
    #dashboard.span12
        = @user.username
        #profile_pic=link_to image_tag(@user.avatar, border: '0'), action: 'profile', controller: 'users'
    #bowl_outline.span9
        Bowl

    #friends.span3
        Friends
        %ul
        - for @user in @friends
            %li
                - if current_user.friend_with? user
                    = user.username
                    |
                    You are already friends!
                - elsif current_user.invited? user
                    = user.username
                    | 
                    Pending request ...
                - elsif user.invited? current_user
                    = user.username
                    |
                    = link_to "Confirm friend?", friend_path(user), :method => "put"
                - else
                    = user.username
                    = link_to "Add friend?", friends_path(:user_id => @user), :method => "post"
  • 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-08T15:05:59+00:00Added an answer on June 8, 2026 at 3:05 pm

    You should not have an instance variable as your for loop variable.

    for user in @friends
    

    I believe @friends = current_user.friends returns an array so it should work with this fix.

    EDIT

    If this is loop is in your user/profile view, you need to have @friends defined in your profile action in your users controller.

    def profile
        @username = params[:id]
        @friends = current_user.friends
        @title = "User Profile for #{@username}"
        @user = User.find_by_username(@username)
        @users = User.all :conditions => ["id != ?", current_user.id]
    end 
    

    and add before_filter :authenticate_user! to your UsersController.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to setup Ember.js with Rails 3.1 and I'm getting the following error
I'm trying to create a Create page for a slightly complex 'view model'/view setup
I'm trying to setup the Widget plugin by wiredesignz at http://codeigniter.com/forums/viewthread/109584/P20 but I keep
I am trying to setup the following view on CouchDB { _id:_design/id, _rev:1-9be2e55e05ac368da3047841f301203d, language:javascript,
I'm quite new to Cocoa and I am trying to setup a table view
I'm trying to set up a custom sort behaviour for my model/view structure in
I have a view that I'm trying to setup an Index for. One of
I'm trying to find a way that my program will show up a setup-view,
im trying to setup two listeners for one button. Here is my code: This
I'm trying to setup an MVVM style application, and I think I'm getting myself

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.