Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete the tag from the tag list of the act_as_taggable plugin?

I have tried to destroy tags from the given code but it's not working. How can it be accomplished?

 @tag = Tag.find_by_name(params[:name])
  @tag.destroy
  render :update do |page|
    page[:divtag].innerHTML = render :partial => "controls/tag_list"
  end
like image 434
Arpit Vaishnav Avatar asked Jan 21 '10 13:01

Arpit Vaishnav


1 Answers

The example you provided seems broken. Normally you have a list of tags belonging to a Model (lets say a User model). Then you could call something like this:

# Find a user
@user = User.find_by_name("Bobby")
# Show available tags
@user.tag_list # => ["awesome", "slick", "hefty"] as TagList
# Remove the "slick" tag
@user.tag_list.remove("slick")
# Store change
@user.save

For more information look at the acts-as-taggable-on readme (unfortunately, removing tags is not explained).

like image 159
Veger Avatar answered Sep 22 '22 14:09

Veger