tagを保存する処理で
class Post < ApplicationRecord has_many :tag_maps, dependent: :destroy, foreign_key: 'post_id' has_many :tags, through: :tag_maps def save_posts(savepost_tags) current_tags = self.tags.pluck(:name) unless self.tags.nil? old_tags = current_tags - savepost_tags new_tags = savepost_tags - current_tags # Destroy old taggings: old_tags.each do |old_name| self.tags.delete Tag.find_by(name:old_name) end # Create new taggings: new_tags.each do |new_name| post_tag = Tag.find_or_create_by(name:new_name) self.tags << post_tag end end end
というコードを書いているのですが
self.tags << post_tag
はどういう処理のコードになるのでしょうか?

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/12 03:26