耙子中止!:name:Symbol 的未定义方法`map' [英] rake aborted! undefined method `map' for :name:Symbol

查看:40
本文介绍了耙子中止!:name:Symbol 的未定义方法`map'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将参数传递给 Rake 任务并访问我的模型,如如何将命令行参数传递给 rake 任务" 和 "rails rake 任务是否提供对 ActiveRecord 模型的访问?".

I'm trying to pass arguments to a Rake task and access my model as mentioned in "How to pass command line arguments to a rake task" and "Do rails rake tasks provide access to ActiveRecord models?".

但是添加 =>:environment 到此代码:

However adding => :environment to this code:

require 'rake'

namespace :genre do
    desc "Add a genre"
    task :add, :genre_id, :name => :environment do |t, args|
        puts args.name  
    end
end

运行任务时出现此错误:

Gives me this error when I run the task:

rake genre:add['1','Abc']
rake aborted!
undefined method `map' for :name:Symbol

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

如果我删除=>:environment 它工作得很好.

If I delete => :environment it works just fine.

更新:

跟踪:

rake --trace genre:add['1','Abc']
rake aborted!
undefined method `map' for :name:Symbol
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:254:in `set_arg_names'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task_manager.rb:29:in `define_task'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:310:in `define_task'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:32:in `task'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/lib/tasks/genre.rake:5:in `block in <top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task_manager.rb:207:in `in_namespace'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:102:in `namespace'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/lib/tasks/genre.rake:3:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `block in load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `each'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/application.rb:145:in `load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/Rakefile:7:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `<main>'

推荐答案

看起来你的语法不对.试试:

Looks like your syntax is off. Try:

task :add, [:genre_id, :name] => :environment do |t, args| 

这篇关于耙子中止!:name:Symbol 的未定义方法`map'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆