Trying to build a friends feature on top of a Solidus framework, but the .friends method does not work. It does in rails console, however.
SpreeUsers Controller (current_spree_user.friends causes error):
class SpreeUsersController < ApplicationController
def my_friends
@friendships = current_spree_user.friends
end
def search
@spree_users = SpreeUser.search(params[:search_param])
render json: @spree_users
end
end
Friendship Model:
class Friendship < ActiveRecord::Base
belongs_to :spree_user
belongs_to :friend, :class_name => 'SpreeUser'
end
SpreeUser Model:
class SpreeUser < ActiveRecord::Base
has_many :friendships
has_many :friends, through: :friendships
end
Error: undefined method `friends' for # Did you mean? friendly_id?
https://i.stack.imgur.com/u4F8K.png
Console Input/Output: