[英]Creating Database Values in a Rake Task - Rails
I have the following script, which I want to automatically update my database. 我有以下脚本,我想自动更新数据库。
require 'feedzirra'
require 'sanitize'
namespace :db do
task :update_pitzer => :environment do
feed = Feedzirra::Feed.fetch_and_parse('http://www.cafebonappetit.com/rss/menu/219')
feed.entries.each do |entry|
date = Sanitize::clean(entry.title)
summary = Sanitize::clean(entry.summary)
summary.gsub!(/\s{2}/, " ").to_s
summary.gsub!(/\s{2}/, "").to_s
summary.gsub!("&", "&")
puts "#{date}"
theDay = Day.create(date: date)
#theDay.collins_meals.create()
array = summary.split(/\[/)
array.collect! {|x| "[" + x}
array.reject! {|x| x == "[ "}
array.to_s
puts array
end
end
end
When I run rake db:update_pitzer at the command line, I get: 当我在命令行上运行rake db:update_pitzer时,我得到:
(in /Users/Alex/rails_projects/dining_hall_api)
rake aborted!
Don't know how to build task 'db:update_pitzer'
Thoughts? 有什么想法吗?
Code seems proper. 代码似乎正确。 Make sure you have put 'update_pitzer.rb' file under 'lib/tasks' folder in your rails application
确保已将“ update_pitzer.rb”文件放在rails应用程序的“ lib / tasks”文件夹下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.