mirror of
https://github.com/danbee/my-images
synced 2025-03-04 08:49:05 +00:00
Delete tags using Stimulus
This commit is contained in:
parent
d71f081d7b
commit
f5bc989048
@ -4,13 +4,12 @@ class TagsController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
image = @current_user.images.find(params[:image_id])
|
image = @current_user.images.find(params[:image_id])
|
||||||
tag = params[:tag]
|
tag = params[:tag]
|
||||||
image.tags << tag unless image.tags.include?(tag)
|
if !image.tags.include?(tag)
|
||||||
image.save
|
image.tags << tag
|
||||||
|
image.save
|
||||||
if request.xhr?
|
|
||||||
render partial: "tags/tag", locals: { image: image, tag: tag }
|
render partial: "tags/tag", locals: { image: image, tag: tag }
|
||||||
else
|
else
|
||||||
redirect_to([:user, image])
|
head 200, content_type: "text/html"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -20,9 +19,6 @@ class TagsController < ApplicationController
|
|||||||
image.tags.delete(tag)
|
image.tags.delete(tag)
|
||||||
image.save
|
image.save
|
||||||
|
|
||||||
respond_to do |format|
|
render json: { status: :ok }
|
||||||
format.html { redirect_to([:user, image]) }
|
|
||||||
format.js { render "index", locals: { image: image, tags: image.tags } }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
<li class="image-tag" id="tag-<%= tag %>">
|
<li class="image-tag"
|
||||||
<%= tag %>
|
id="tag-<%= tag %>"
|
||||||
<%= link_to "×".html_safe,
|
data-controller="tag">
|
||||||
user_image_tag_path(image, tag),
|
<span data-target="tag.name"><%= tag %></span>
|
||||||
method: :delete,
|
<%= link_to "×".html_safe,
|
||||||
remote: true,
|
user_image_tag_path(image, tag),
|
||||||
class: "delete-tag" %>
|
data: { action: "click->tag#delete" },
|
||||||
|
class: "delete-tag" %>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user