0

これが私の方法です:

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、記事に新しいタグを追加することですが、古いタグを削除していないことです.

4

1 に答える 1

0

私が直面していた問題は、タグを更新すると、関連するすべてのモデルの検証が開始されることです。私の場合、開発マシンで画像が利用できないために検証が失敗し、添付ファイルの検証が失敗していました。

検証を無視するには、次のようにします。

article.save(:validate => false)
于 2013-01-30T12:51:05.743 に答える