here come the tags
This commit is contained in:
parent
c8732b6332
commit
29368bfdb9
16 changed files with 155 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue