Gem mlb 的 seeds 怎么导入数据库。

dreamrise · 2012年03月27日 · 最后由 dreamrise 回复于 2012年03月28日 · 3735 次阅读
require 'mlb'

User.create(:email => '[email protected]', :password => 'password', :password_confirmation => 'password')

MLB::Team.all.each do |mlb_team|
  unless league = RailsAdmin::AbstractModel.new("League").first(:conditions => ["name = ?", mlb_team.league])
    league = RailsAdmin::AbstractModel.new("League").create(:name => mlb_team.league)
  end
  unless division = RailsAdmin::AbstractModel.new("Division").first(:conditions => ["name = ?", mlb_team.division])
    division = RailsAdmin::AbstractModel.new("Division").create(:name => mlb_team.division, :league => league)
  end
  unless team = RailsAdmin::AbstractModel.new("Team").first(:conditions => ["name = ?", mlb_team.name])
    team = RailsAdmin::AbstractModel.new("Team").create(:name => mlb_team.name, :logo_url => mlb_team.logo_url, :manager => mlb_team.manager, :ballpark => mlb_team.ballpark, :mascot => mlb_team.mascot, :founded => mlb_team.founded, :wins => mlb_team.wins, :losses => mlb_team.losses, :win_percentage => ("%.3f" % (mlb_team.wins.to_f / (mlb_team.wins + mlb_team.losses))).to_f, :division => division)
  end
  mlb_team.players.reject{|player| player.number.nil?}.each do |player|
    RailsAdmin::AbstractModel.new("Player").create(:name => player.name, :number => player.number, :position => player.position, :team => team)
  end
end

MLB: https://github.com/sferik/mlb

对于项目中的 db/seeds.rb,用 rake db:seeds 导入数据报错:

D:\work\dummy_app>rake db:seeds rake aborted! Don't know how to build task 'db:seeds'

(See full trace by running task with --trace)

这要怎么才能导入数据?

MLB.rb is a Ruby library for retrieving current Major League Baseball players, managers, teams, divisions, and leagues

你试下 rake db:seed 我在看 web 敏捷开发,上面有歌也是 seeds.rb 的文件,执行的时候命令是 rake db:seed,如果执行 rake db:seeds 就报错,我也不知道为啥

#3 楼 @Crabby 我是根据书上的命令做的,rake db:seed 一点问题都没有 ~

D:\work\dummy_app>rake db:seed rake aborted! undefined method `create' for #RailsAdmin::AbstractModel:0x4fc0ff8

Tasks: TOP => db:seed (See full trace by running task with --trace)

在官网发了个询问,被告知:

mshibuya commented an hour ago RailsAdmin::AbstractModel#create was removed in some point, so db:seed was not working until I've fixed that in 566270a. Updating your RailsAdmin to the latest master should solve this.

https://github.com/sferik/rails_admin/issues/1050

需要 登录 后方可回复, 如果你还没有账号请 注册新账号