Reputation: 5682
Have already looked at this stack question, at which point I looked at all of the links in the answer.
Created custom rake task, code looks like this:
task :seeding do
op_a = CoverageDetail.create(option: 'a', privacy_and_website_media: 250000.00, privacy_breach_service: 20000,
legal_forensic_cost: 25000.00, call_center_service: 'inc', deductible: 5000.00,
credit_monitoring_individuals: 20000, fraud_resolution_service: 5000, regulatory_defense: 100000.00,
pci_fines_and_costs: 50000.00, crisis_management_and_pr: 50000.00, foreign_notification: 10000.00)
op_b = CoverageDetail.create(option: 'b', privacy_and_website_media: 500000.00, privacy_breach_service: 25000,
legal_forensic_cost: 50000.00, call_center_service: 'inc', deductible: 5000.00,
credit_monitoring_individuals: 25000, fraud_resolution_service: 5000, regulatory_defense: 250000.00,
pci_fines_and_costs: 50000.00, crisis_management_and_pr: 50000.00, foreign_notification: 10000.00)
op_c = CoverageDetail.create(option: 'c', privacy_and_website_media: 1000000.00, privacy_breach_service: 50000,
legal_forensic_cost: 100000.00, call_center_service: 'inc', deductible: 5000.00,
credit_monitoring_individuals: 50000, fraud_resolution_service: 5000, regulatory_defense: 500000.00,
pci_fines_and_costs: 50000.00, crisis_management_and_pr: 50000.00, foreign_notification: 10000.00)
op_a.save!
op_b.save!
op_c.save!
end
I have a table called coverage_details I have a model called coverage_detail.rb I have a controller called coverage_details_controller.rb. The class name in the model is CoverageDetail.
Problem: Why am I getting uninitialized constant CoverageDetail
?
This is my first time trying to create a custom rake task to seed a new table in an existing app, or I would just add this info to my db:seed file.
What am I missing?
Upvotes: 0
Views: 218
Reputation: 6384
use environment to give it rails environment
task :seeding => :environment do
op_a = CoverageDetail.create(option: 'a', privacy_and_website_media: 250000.00, privacy_breach_service: 20000,
legal_forensic_cost: 25000.00, call_center_service: 'inc', deductible: 5000.00,
credit_monitoring_individuals: 20000, fraud_resolution_service: 5000, regulatory_defense: 100000.00,
pci_fines_and_costs: 50000.00, crisis_management_and_pr: 50000.00, foreign_notification: 10000.00)
op_b = CoverageDetail.create(option: 'b', privacy_and_website_media: 500000.00, privacy_breach_service: 25000,
legal_forensic_cost: 50000.00, call_center_service: 'inc', deductible: 5000.00,
credit_monitoring_individuals: 25000, fraud_resolution_service: 5000, regulatory_defense: 250000.00,
pci_fines_and_costs: 50000.00, crisis_management_and_pr: 50000.00, foreign_notification: 10000.00)
op_c = CoverageDetail.create(option: 'c', privacy_and_website_media: 1000000.00, privacy_breach_service: 50000,
legal_forensic_cost: 100000.00, call_center_service: 'inc', deductible: 5000.00,
credit_monitoring_individuals: 50000, fraud_resolution_service: 5000, regulatory_defense: 500000.00,
pci_fines_and_costs: 50000.00, crisis_management_and_pr: 50000.00, foreign_notification: 10000.00)
op_a.save!
op_b.save!
op_c.save!
end
The environment gives it rails running environment and Your model CoverageDetail comes in the scene.
thanks
Upvotes: 5