Commit e016d4cd93dfb7af32832c968a527049d9a732ee

Authored by Rodrigo Souto
1 parent 50fc6378

rails3: fix mass-assignment for article copy

Showing 1 changed file with 10 additions and 2 deletions   Show diff stats
app/models/article.rb
@@ -518,13 +518,21 @@ class Article < ActiveRecord::Base @@ -518,13 +518,21 @@ class Article < ActiveRecord::Base
518 def copy(options = {}) 518 def copy(options = {})
519 attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } 519 attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) }
520 attrs.merge!(options) 520 attrs.merge!(options)
521 - self.class.create(attrs) 521 + object = self.class.new
  522 + attrs.each do |key, value|
  523 + object.send(key.to_s+'=', value)
  524 + end
  525 + object.save
522 end 526 end
523 527
524 def copy!(options = {}) 528 def copy!(options = {})
525 attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } 529 attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) }
526 attrs.merge!(options) 530 attrs.merge!(options)
527 - self.class.create!(attrs) 531 + object = self.class.new
  532 + attrs.each do |key, value|
  533 + object.send(key.to_s+'=', value)
  534 + end
  535 + object.save!
528 end 536 end
529 537
530 ATTRIBUTES_NOT_COPIED = [ 538 ATTRIBUTES_NOT_COPIED = [