Skip to content

Instantly share code, notes, and snippets.

@PratheepV
Created September 5, 2015 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PratheepV/504f39176ee43032b5ec to your computer and use it in GitHub Desktop.
Save PratheepV/504f39176ee43032b5ec to your computer and use it in GitHub Desktop.
To enable validations on seed fu
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