这是我的方法:
def rename
old_tag = params[:old_tag]
new_tag = params[:new_tag]
if old_tag != new_tag
# find any articles that use the old tag
Article.tagged_with(old_tag).each do |article|
# give articles with the old tag the new tag
article.tag_list.add(new_tag)
# remove the old tag
article.tag_list.remove(old_tag)
article.save
end
end
render :json => "#{old_tag} renamed to #{new_tag}"
end
我遇到的问题是.save
在文章中添加了一个新标签,但没有删除旧标签。