1

我有以下脚本,我想自动更新我的数据库。

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'

想法?

4

1 回答 1

0

代码似乎正确。确保您已将“update_pitzer.rb”文件放在 Rails 应用程序的“lib/tasks”文件夹下

于 2012-04-30T10:31:09.183 回答