我有以下脚本,我想自动更新我的数据库。
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
当我在命令行运行rake db:update_pitzer时,我得到:
(in /Users/Alex/rails_projects/dining_hall_api)
rake aborted!
Don't know how to build task 'db:update_pitzer'
思想?
答案 0 :(得分:0)
代码似乎是正确的。确保已将“update_pitzer.rb”文件放在rails应用程序的“lib / tasks”文件夹下