From: Eric Wollesen Date: 2011-01-21T08:20:24+09:00 Subject: Re: help on find over find On Jan 20, 4:05 pm, Mauricio Alcayaga wrote: > hi all > > I have a problem trying to do the following: > > MyModel.find(:all).find(:first) > > it can look weird or unnecesary but this is the short explanation, > extended one is: > > I have a helper method, this receives a collection an return some html, > this helper works fine if that collection is an association (has_many) > of a model but doesn't work if it is a direct find over a model > > the error I receive is "LocalJumpError: no block given" > > ultra mega extended explanation is: > > a model: > > class User < ActiveRecord::Base >  has_many :requests > end > > other model: > > class Request < ActiveRecord::Base >  def unRequested >   find(:all, conditions => {:state => "unrequested"}) >  end > end > > the helper > module ApplicationHelper >  def yearsCalendar (collection) >   years = collection.find(:all, :select => "YEAR(date_created) AS > years") >   years.each do |y| >    html << "
#{y}
" >   end >  end > end > > finally at view: > <%= yearsCalendar(User.requests) # WORKS FINE %> > > <%= yearsCalendar(Request.unRequested) #WONT WORK , RETURN ERROR: > "LocalJumpError: no block given" %> > > any help?, thanks in advance > > -- > Posted viahttp://www.ruby-forum.com/. The objects returned by find(:all, ...) and User.requests are different, and have different APIs. In particular, find(:all) returns an array, which has a find method defined on it, but it's find method is very different from the find on an ActiveRecord class. You might consider changing your yearsCalendar method to look more like this: def yearsCalendar (collection) years = collection.map {|c| Time.parse(c.date_created).year} years.inject("") {|c, i| c << content_tag("div", i)} end This avoids the fact that the collections are different classes, and instead uses what they have in common, ie that they both inherit the Enumerable module. Good luck, e.