I have two models: User and User_profile
In User.rb, User has_one :user_profile.
In User_profile.rb, User_profile belongs_to :user.
Then I have users_controller and its index.html.erb.
So I added this to my User model in order to enable search by nested column, but it shows an error when I try to reindex. How can I fix this?
undefined method `user_profiles’ for #
models/user.rb
....
searchable do
text :user_profile_nickname do
user_profiles.map { |user_profile| user_profile.nickname }
end
end
....
You have given User
has_one :user_profilein your user.rb file. So it can’t be collection of objects, rather it is a member object. So you can not calluser_profiles.map { |user_profile| user_profile.nickname }in your User model.If you want to call write as following:
The above will work for sure. Do let me know if not working.