Rails Against The Machine

Just a mind dump. Why are you even reading this?

Tuesday, 21 August 2007

 

Ruby gotcha 1

If I have an active record model say a 'venue' has many 'opening_times'

def edit
@venue = Venue.find(params[:id])
end

In the view I can access this by times=@venue.opening_times
but this is not an array since

times.find_all{|x| false}

returns the all the opening times not zero as would be expected.

however

an_array=times.to_a
an_array.find_all{|x| false}

behaves as expected as does:

an_array=Array.new
times.each{|x| an_array<

http://www.railsweenie.com/forums/5/topics/1306 goes into it in more depth

unlike him however I find that

an_array.method(:find_all).call{|x| x.monday==true}

does work as expected

as does an_array.send(:find_all){|x| x.monday==false}





Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

Archives

July 2007   August 2007   September 2007   December 2007   January 2008   February 2008   March 2008   April 2008   June 2008   July 2008   August 2008   October 2008   November 2008   January 2009  

This page is powered by Blogger. Isn't yours?

Subscribe to Comments [Atom]