I have the usual many-to-many relationship:
class Post < ApplicationRecord
has_many :posts_and_images
has_many :images, through: :posts_and_images
end
class PostsAndImage < ApplicationRecord
belongs_to :post
belongs_to :image
end
class Image < ApplicationRecord
has_many :posts_and_images
has_many :posts, through: :posts_and_images
end
I added a field to the posts_and_images
table. And now I can't understand how I can work with this field.
For example, I added a description
field to the posts_and_images
table. That is, this field with a unique description for each image of each post.
I want to work with this field like this:
- @post.images.each do |image|
/ ...
= content_tag :div, image.description
Tell me, please, how can I achieve this result?