I have done this a million times and yet I can't seem to figure out why it is not working now. I have a user model that has_one profile. The profile belongs_to the user model. In my profile controller, I am trying to access all the profiles that belong to a subset of users but I can't seem to. I have tried this:
def index
if params[:tag]
@profiles = Profile.user.tagged_with(params[:tag])
else
@profiles = Profile.all
end
end
I am getting the error that the method user is undefined. Yet, in views, I have called @profiles.user and it works fine. I have also tried:
def index
if params[:tag]
@profiles = Profile.users.tagged_with(params[:tag])
else
@profiles = Profile.all
end
end
but that does not work. Please help. Thanks.
EDIT:
class User < ActiveRecord::Base
has_one :profile
acts_as_taggable
end
class Profile < ActiveRecord::Base
belongs_to :user
end