Staff spaces...

Colin Jones

Web Developer

undefined method `last' for {}:Hash

Posted on 02/22/2008 by Colin
comment bubble4 Comments

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

Comments

Posted by Joel Nylund on March 04, 2008

Hi, did you mean to remove the add.comment from outside the if statement?

Posted by Colin on March 17, 2008

Ack---I certainly did. Thanks for the sharp eye! I've amended it above to match the actual code in my applications!

Posted by Roderic on April 11, 2008

This code doesn't handle prerequisities well. resolveargs returns now triplet of [taskname, arg_names, deps], so code should be: def redefinetask(taskclass, args, &block) taskname, argnames, deps = (RAKEVERSION >= '0.8.0') ? resolveargs([args]) : resolveargs(args) ... ...

or even

def redefinetask(taskclass, *args, &block) taskname, argnames, deps = resolve_args(args) ... ...

Posted by Andrew Threlfall on April 22, 2008

Thanks for the post, fixed the problem I had

Post a Comment

Name

Comment

192

Space Highlight

Trumpet player

583

I created a site for my trumpet playing and teaching - check it out. I play for weddings and other events!

flickr

SupportSupport

Pay OnlinePay Online

Contact UsContact Us

Ruby on Rails
Ruby on Rails Web Development

Plexus Web Creations builds custom, rich internet applications on the Ruby on Rails web application framework.

ProductCart
ProductCart E-Commerce Developer

Plexus Web Creations provides ProductCart Shopping Cart for e-commerce web sites.