모든 태그를 삭제하려는 경우 delete_all
을 관계로 보낼 수 있습니다.
짧은 예를
> resource.grades.delete_all
> resource.reload
> resource.grades
=> []
긴 예를
> resource.grades
=> [#<ActsAsTaggableOn::Tag id: 336486, name: "Kindergarten", context: nil, sort: 0>,
#<ActsAsTaggableOn::Tag id: 336506, name: "Pre-K", context: nil, sort: 0>]
> resource.grades.delete_all
(0.3ms) BEGIN
SQL (0.5ms) DELETE FROM `taggings` WHERE `taggings`.`taggable_id` = 984643 AND `taggings`.`taggable_type` = 'Resource' AND `taggings`.`tag_id` IN (336486, 336506) AND (taggings.context = 'grades')
(0.2ms) COMMIT
=> [#<ActsAsTaggableOn::Tag id: 336486, name: "Kindergarten", context: nil, sort: 0>,
#<ActsAsTaggableOn::Tag id: 336506, name: "Pre-K", context: nil, sort: 0>]
> resource.reload
Resource Load (0.6ms) SELECT `resources`.* FROM `resources` WHERE `resources`.`id` = 984643 LIMIT 1
=> #<Resource id: ...>
> resource.grades
ActsAsTaggableOn::Tag Load (0.6ms) SELECT `tags`.* FROM `tags` INNER JOIN `taggings` ON `tags`.`id` = `taggings`.`tag_id` WHERE `taggings`.`taggable_id` = 984643 AND `taggings`.`taggable_type` = 'Resource' AND (taggings.context = 'grades')
=> []
* act_as_tagg * 플러그인이란 무엇입니까? 그것에 대해 더 많은 정보를 제공해 주시겠습니까? '@ tag.destroy'는 태그를 지워야하기 때문에 다른 태그가 간섭해야합니다. – Veger
Heh가 실수로 우연히 발견 : acts-as-taggable-on 질문의 제목을 변경하는 것이 더 편할 것입니다. – Veger
예 친구, 그 같은 행위는 "taggable"행위로 간주됩니다. 과 같은 오류가 표시됩니다. "0을 Fixnum에 강제 적용 할 수 없습니다." –