2012-09-19 2 views
7

Sto provando a passare argomenti a un'attività Rake e ad accedere al mio modello come menzionato in" How to pass command line arguments to a rake task "e" Do rails rake tasks provide access to ActiveRecord models? ".rastrello interrotto! metodo non definito `map 'per: nome: Simbolo

Tuttavia l'aggiunta di => :environment a questo codice:

require 'rake' 

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

mi dà questo errore quando ho eseguito il compito:

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

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

Se cancello => :environment funziona bene.


UPDATE:

TRACE:

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>' 
+0

puoi fornire traccia. –

risposta

20

Sembra che la sintassi è spento. Prova:

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

Primo: funziona magnificamente. Secondo: ATTENZIONE: 'task: t, arg,: needs => [deps]' è deprecato. Per favore usa 'task: t, [args] => [deps]' invece. – Snowcrash

+0

non usare:: ... usa solo task: foo, [: arg1,: arg2] => [: bar] – nterry