here come the tags

This commit is contained in:
Roscoe 2025-09-10 03:46:23 +01:00
commit 29368bfdb9
Signed by: RoscoeDaWah
SSH key fingerprint: SHA256:Hqn452XQ1ETzUt/FthJu6+OFkS4NBxCv5VQSEvuk7CE
16 changed files with 155 additions and 2 deletions

View file

@ -15,6 +15,13 @@ class ClipsController < ApplicationController
def create
@clip = Clip.new(clip_params)
if @clip.save
params[:clip][:tag_ids].each do |tag_id|
unless tag_id.empty?
tag = Tag.find(tag_id)
@clip.tags << tag
end
end
redirect_to @clip
else
render :new, status: :unprocessable_entity
@ -24,8 +31,25 @@ class ClipsController < ApplicationController
def edit
end
def update
def update
if @clip.update(clip_params)
newtags = []
params[:clip][:tag_ids].each do |tag_id|
unless tag_id.empty?
tag = Tag.find(tag_id)
newtags.push(tag)
unless @clip.tags.include? tag
@clip.tags << tag
end
end
end
@clip.tags.each do |tag|
unless newtags.include? tag
@clip.tags.delete tag
end
end
redirect_to @clip
else
render :edit, status: :unprocessable_entity