#apache #archlinux #asterisk #centos #debian #gentoo #haskell #kde #kubuntu #lisp #math #mysql #perl #python #ruby-lang #rubyonrails #suse #ubuntu #vim #wikipedia 0 1 2 3 4 5 6 7 8 9 10
Top Prev 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 Next
#rubyonrails
<ReinH> I look at it as a poor code smell personally
<smtlaissezfaire> really?! Had no idea
<invalid8> it works. thanks ReinH. I'll have to read up more on render
<ReinH> It's there to help people from languages with the for loop construct
<ReinH> It actually uses each interally
<smtlaissezfaire> well, isn't it written in C?
<ReinH> like if you do for foo in nil it will complain that NilClass doesn't have an each method
<smtlaissezfaire> So in a way, really .each is a for loop
<ReinH> .each is far better than the for loops in other languages though
<ReinH> foreach in PHP is a joke
<smtlaissezfaire> oh, of course. Man, I hated that C junk: for(x=1; x <= 55; x++) { .... }
<ReinH> .each also allows the enumerable mixin to do lots of cool stuff
<wilfordbrimley> sorry to keep asking this not sure if anyone knows but why does the has_many association redefine Array.find
<ReinH> .each and <=> allow sort and sort_by and etc
<ReinH> each_with_index
<ReinH> and so on
<smtlaissezfaire> wilfordbrimley: why shouldn't it declare a method called find() ?
<ReinH> in fact, any class with .each <=> and enumerable mixed in gets all the ect methods for free
<ReinH> and with comparable they get sort and sort_by and such for free
<ReinH> it's genius
<ReinH> I've seen huge Java classes that just implement .each
<wilfordbrimley> smtlaissezfaire: well it should by Array#find but it actually calls ActiveRecord::Base#find
<smtlaissezfaire> you mean mixins and single inheritence
<ReinH> wilfordbrimley: use detect if you want Array#find
<ReinH> wilfordbrimley: in rails, it's a good idea to use the *ect methods any time you want to use the Array instance methods, to disambiguate
<wilfordbrimley> ReinH: awesome, thanks... is that just a rails alias to Array#find
<ReinH> wilfordbrimley: no, it's ruby as well
<ReinH> detect, select, reject, collect, inject
<ReinH> are all unambiguously methods of Array
<smtlaissezfaire> I was wondering what you meant by the *etc method
<ReinH> well, actually some are Enumerable methods
<ReinH> but they won't be confused for Rails methods
<wilfordbrimley> ReinH: awesome, thx. whats the reason for redefining Array#find with the has_many assoc.?
<ReinH> wilfordbrimley: so you can do cart.items.find(:all, :conditions => 'items.price > 500') and such
<ReinH> to do select * from items where cart_id = items.cart.id and items.price > 500 (something like it at least)
<wilfordbrimley> ReinH: ah. ok.
<ReinH> er items.cart_id = cart.id rather
<ReinH> you can leverage the association to scope the find
<wilfordbrimley> ReinH: ok, yeah it seemed counter intuitive at first since find is a class method
<arooni> im getting an error that no test cases are available for my UserNotifier model... but i can clearly seem them in the unit test directory... what gives?
<ReinH> it would be like doing Item.find(:all, :conditions => ["items.price > 500 and items.cart_id = ?", cart.id])
<tavilach> guys, i wanted to change human_name
<tavilach> so i downloaded the plugin
<tavilach> but it doesnt work for column listings
<ReinH> column listings?
<tavilach> it changes "body" to "joke body" in validation messages
<tavilach> but not, say, in the scaffold titles
<ReinH> tavilach: right, so don't use the scaffolding
<tavilach> but why doesnt it work?
<tavilach> scaffolding uses
Previous Page Next Page