What is the preferred way of selecting a specific record out of a has_many relation for a specific model in Rails? (I'm using Rails 5.)
I have a model User
and a model Picture
which are related via the following code:
class User < ApplicationRecord
has_many :pictures, as: :imageable
# ...
end
class Picture < ApplicationRecord
belongs_to :imageable, polymorphic: true
# ...
end
What I want to do is to allow a User
to set a profile picture from the images associated with it, so I can call @user.profile_picture
on a User
object and retrieve the profile picture.