Commit e016d4cd93dfb7af32832c968a527049d9a732ee
1 parent
50fc6378
Exists in
master
and in
29 other branches
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 | 518 | def copy(options = {}) |
519 | 519 | attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } |
520 | 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 | 526 | end |
523 | 527 | |
524 | 528 | def copy!(options = {}) |
525 | 529 | attrs = attributes.reject! { |key, value| ATTRIBUTES_NOT_COPIED.include?(key.to_sym) } |
526 | 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 | 536 | end |
529 | 537 | |
530 | 538 | ATTRIBUTES_NOT_COPIED = [ | ... | ... |