Icon_search
Colin

undefined method `last' for {}:Hash

Posted on 02/22/2008 by Colin
 | 

Sometimes you hate the things that make your life so easy, because you have some problems with those things that make it temporarily more difficult. But then you fix the problems, and everything's back to being cool again.

In this case, I'm using Engines with Ruby on Rails, and there seems to be a conflict between my version of rake and my version of engines. So I did a rake db:migrate and got the ugly-looking:

undefined method `last' for {}:Hash

on line 10 of the rakefile. Well, after some Googling and clicking through, I found that all I needed to do was update a few lines of the engines code. In /vendor/plugins/engines/tasks/engines.rake, change the redefine_task method to read as follows:

def redefine_task(task_class, args, &block)
   task_name, deps = (RAKEVERSION >= '0.8.0') ? resolve_args([args]) : resolve_args(args)
   task_name = task_class.scope_name(@scope, task_name)
   deps = [deps] unless deps.respond_to?(:to_ary)
   deps = deps.collect {|d| d.to_s }
   task = @tasks[task_name.to_s] = task_class.new(task_name, self)
   task.application = self
   if RAKEVERSION >= '0.8.0'
     task.add_description(@last_description)
     @last_description = nil
   else
     task.add_comment(@last_comment)
     @last_comment = nil
   end
   task.enhance(deps, &block)
   task
end

Tagged:  undefined method, rails, engines, rake