From e016d4cd93dfb7af32832c968a527049d9a732ee Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Fri, 13 Sep 2013 19:45:13 +0000 Subject: [PATCH] rails3: fix mass-assignment for article copy --- app/models/article.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 6dd0a3f..1d485f0 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -518,13 +518,21 @@ class Article < ActiveRecord::Base def copy(options = {}) attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } attrs.merge!(options) - self.class.create(attrs) + object = self.class.new + attrs.each do |key, value| + object.send(key.to_s+'=', value) + end + object.save end def copy!(options = {}) attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } attrs.merge!(options) - self.class.create!(attrs) + object = self.class.new + attrs.each do |key, value| + object.send(key.to_s+'=', value) + end + object.save! end ATTRIBUTES_NOT_COPIED = [ -- libgit2 0.21.2