Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
darius goore
3,803 PointsRake task question
I sometimes get an error when I try to run a rake task, "Don't know how to build task..."
Can someone explain how to solve this?
Secondly, I am attempting to write a rake task to pull data from a csv file to edit existing records in a table. I have a draft but perhaps due to question 1 i am not sure if I have it right.
2 Answers
darius goore
3,803 Pointsok i think I fixed question 1, but the data is not updated after the task runs.
here is the task as written now:
desc "Add-Edit xxxx as specified in xxxx_data_edit_list.csv file" task :edit_data_existing_listings => :environment do p "Task started!" filepath = File.dirname FILE if Rails.env == 'production' file_name = "/xxxx_data_edit_list.csv" end CSV.foreach(filepath + file_name, headers: true) do |xxxx| xxxxs = xxxx.to_hash xxxx_obj = Xxxx.find_by_id(xxxxs["xxxx_id"]) unless xxxx_obj.nil? xxxx_obj.name = xxxx.title xxxx_obj.description = xxxx.description xxxx_obj.email = xxxx.email xxxx_obj.save end end p "Done!" end
I get Done! but nothing is changed. I think I am using find_by_id incorrectly but not sure.
darius goore
3,803 PointsStill working on this the task runs, i get no method errors for name, description etc and rake is aborted