Created
September 5, 2015 06:12
-
-
Save PratheepV/504f39176ee43032b5ec to your computer and use it in GitHub Desktop.
To enable validations on seed fu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SeedFu | |
class Seeder | |
private | |
def seed_record(data) | |
record = find_or_initialize_record(data) | |
return if @options[:insert_only] && !record.new_record? | |
puts " - #{@model_class} #{data.inspect}" unless @options[:quiet] | |
# Rails 3 or Rails 4 + rails/protected_attributes | |
if record.class.respond_to?(:protected_attributes) && record.class.respond_to?(:accessible_attributes) | |
record.assign_attributes(data, :without_protection => true) | |
# Rails 4 without rails/protected_attributes | |
else | |
record.assign_attributes(data) | |
end | |
# just removed the validation: false | |
record.save || raise(ActiveRecord::RecordNotSaved, 'Record not saved!') | |
record | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment