From: Mauricio Alcayaga Date: 2011-09-02T03:31:41+09:00 Subject: Re: help on find over find hi Eric, hope don't bother you, I followed your suggestion and I have had success I ended up with the following funtcion @activityPeriods = coleccion.map{ |x| [x.date_created.year, x.date_created.month] }.uniq as you can see, I'm getting an array of two columns [years, months] extracted from a collection's (named "coleccion") asking over the field "date_created" question: do you know a way, using similar structure, to introduce a variable as field name to generate the response ? , I mean in te way of: @activityPeriods = coleccion.map{ |x| [x.VARIABLEFIELDNAME.year, x.VARIABLEFIELDNAME.month] }.uniq hope you can help, thanks in advance Eric Wollesen wrote in post #976398: > On Jan 20, 4:05pm, Mauricio Alcayaga wrote: >> this helper works fine if that collection is an association (has_many) >> end >> module ApplicationHelper >> <%= 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. -- Posted via http://www.ruby-forum.com/.