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
|
||||
image = @current_user.images.find(params[:image_id])
|
||||
tag = params[:tag]
|
||||
image.tags << tag unless image.tags.include?(tag)
|
||||
image.save
|
||||
|
||||
if request.xhr?
|
||||
if !image.tags.include?(tag)
|
||||
image.tags << tag
|
||||
image.save
|
||||
render partial: "tags/tag", locals: { image: image, tag: tag }
|
||||
else
|
||||
redirect_to([:user, image])
|
||||
head 200, content_type: "text/html"
|
||||
end
|
||||
end
|
||||
|
||||
@ -20,9 +19,6 @@ class TagsController < ApplicationController
|
||||
image.tags.delete(tag)
|
||||
image.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to([:user, image]) }
|
||||
format.js { render "index", locals: { image: image, tags: image.tags } }
|
||||
end
|
||||
render json: { status: :ok }
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
<li class="image-tag" id="tag-<%= tag %>">
|
||||
<%= tag %>
|
||||
<%= link_to "×".html_safe,
|
||||
user_image_tag_path(image, tag),
|
||||
method: :delete,
|
||||
remote: true,
|
||||
class: "delete-tag" %>
|
||||
<li class="image-tag"
|
||||
id="tag-<%= tag %>"
|
||||
data-controller="tag">
|
||||
<span data-target="tag.name"><%= tag %></span>
|
||||
<%= link_to "×".html_safe,
|
||||
user_image_tag_path(image, tag),
|
||||
data: { action: "click->tag#delete" },
|
||||
class: "delete-tag" %>
|
||||
</li>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user