From: arnaud stageman Date: 2006-06-13T18:47:12+09:00 Subject: Re: ugly ruby code... Kroeger, Simon (ext) wrote: >> -----Original Message----- >> From: list-bounce@example.com >> [mailto:list-bounce@example.com] On Behalf Of arnaud stageman >> Sent: Tuesday, June 13, 2006 10:33 AM >> To: ruby-talk ML >> Subject: ugly ruby code... >> >> I would like to seperate racks already added in the showed >> room and the others >> [...] > > This looks like active record, right? > > what about > > def show > @room = Room.find(params[:id]) > @racks_room = Rack.find(:all, :conditions => "room_id = #{@room.id}") > @free_racks = Rack.find(:all, :conditions => "room_id != #{@room.id}") > end > > cheers > > Simon It would be better : def show @room = Room.find(params[:id]) @racks_room = Rack.find(:all, :conditions => ["room_id = ?", @room.id]) @free_racks = Rack.find(:all, :conditions => ["room_id != ?", @room.id]) end Because you avoid sql injection. The first solution is better because you execute only one sql request. -- Posted via http://www.ruby-forum.com/.