I use the acts-as-taggable-on gem with only one (default) tag list. I wonder whether it is possible to create a form to manage tags with the following features. (Went through all answers and only found solutions for Activeadmin.)
How would I construct the two forms 1-3 and 4? Is that at all possible with acts_as_taggable? Thanks for any hint in advance.
Solved it myself.
form_tag "/tags" do
text_field_tag :name
submit_tag "Add tag"
@tags.each do |tag|
text_field_tag "tags[#{tag.id}]name", tag.name, class: 'name'
<button class="update-tag radius small">Save</button>
<button class="delete-tag radius small">Delete</button>
$(function(){
$(".delete-tag").on("click", function(){
var row = $(this).closest("tr");
$.post("/tags/" + row.data("id"), {_method: "DELETE"}, function(){
row.remove();
})
})
$(".update-tag").on("click", function(){
var row = $(this).closest("tr");
$.post("/tags/" + row.data("id"), {_method: "PUT", name: row.find('.name').val()})
})
})
class TagsController < ApplicationController
def create
name = params[:name]
ActsAsTaggableOn::Tag.create(name: name)
redirect_to :back
end
def destroy
tag = ActsAsTaggableOn::Tag.find(params[:id])
tag.destroy
render json: {success: true}
end
def update
tag = ActsAsTaggableOn::Tag.find(params[:id])
tag.update_attributes(name: params[:name])
render json: {success: true}
end
end