[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-12 Thread Marnen Laibow-Koser
Mark Horrocks wrote: Bb Serviss wrote:   Many thanks to everyone who replied, this is a great forum. Delphi has  been kind to me with the (visual component library) client data set  which allows me to make a single query, then scope the remaining records  in any way I see fit and loop through

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-12 Thread Mark Horrocks
Marnen Laibow-Koser wrote: Mark Horrocks wrote: Bb Serviss wrote:   Delphi has been unkind to you, then.  That's a bad way to interact with a database.  In general, it is much better practice to have the DB narrow down the data as much as possible and loop through as few records as

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-12 Thread Marnen Laibow-Koser
Mark Horrocks wrote: Marnen Laibow-Koser wrote: Mark Horrocks wrote: Bb Serviss wrote:   Delphi has been unkind to you, then.  That's a bad way to interact with a database.  In general, it is much better practice to have the DB narrow down the data as much as possible and loop through as

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-12 Thread Mark Horrocks
Marnen Laibow-Koser wrote: Hmm. You *could* do a line-by-line port, then refactor to a more Railsy architecture -- but it will be a herculean refactoring. Rewriting to the new architecture from scratch will probably be easier. I will do it from scratch. The algorithms for game draws and

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-12 Thread Agoofin
I use Delphi (Lazarus) at work and I constantly miss ruby features :) I can only echo Marnen's remarks about Rails, Delphi does some weird things and I've found that doing it the Rails way is usually simpler and much more efficient. As far as the bookings, you should do a bottom up review by

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-12 Thread Mark Horrocks
Bb Serviss wrote: I use Delphi (Lazarus) at work and I constantly miss ruby features :) I still use Delphi 7 because later versions don't like some of the com stuff in the app exe. Its a nightmare just to refactor that. I have numerous third party dependencies like patches to Internet Express

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread Agoofin
There are a few ways to do this. One would be using a named_scope in Rails 2 or just plain scope in Rails 3 class Bookings ActiveRecord::Base named_scope :discount, :conditions = { :discount .5 } I like to model class methods for pulling specific information from the database def

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread Mark Horrocks
Thanks for your reply. A couple of further comments / question. I am a noob in Rails. I like to model class methods for pulling specific information from the database def self.inactive find( :all, :conditions = [inactive = ?, 1], :order = :last_calibrated_on ) end And then in

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread Mark Horrocks
Marnen Laibow-Koser wrote: If you have 1000 records that you're paging through 10 at a time, there is no reason to fetch all 1000 if you only want to read 10. There aren't anywhere near that many. Its just that I change the view of the records returned many times while testing for a game

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread Marnen Laibow-Koser
Mark Horrocks wrote: Marnen Laibow-Koser wrote: If you have 1000 records that you're paging through 10 at a time, there is no reason to fetch all 1000 if you only want to read 10. There aren't anywhere near that many. Its just that I change the view of the records returned many times

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread Marnen Laibow-Koser
Mark Horrocks wrote: Marnen Laibow-Koser wrote: I'm still not completely sure I understand  exactly what you're doing,  but it looks to me like you're running onto trouble because you're    If I want to re book courts after a game redraw part of the way through  a competition, its necessary

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread Mark Horrocks
Marnen Laibow-Koser wrote: Huh?  A Rails recordset is simply an array.  You can take a piece of it just as you would from any other Ruby array.  There's no explicit SetRange because you can just use array slicing.  Thanks! I guess this is just what I am looking for. Setrange gives the

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread lardawge
It might help you a bunch to think of it as Ruby and not Rails. Most of what your doing is writing Ruby and in many situations you will need to know how. Look through the Array methods here and you should get an idea of what can be done; http://ruby-doc.org/core/classes/Array.html Rails also

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread Agoofin
And then in the controller: @inactive = Item.inactive This looks like it will still fire off a query which is what I want to avoid. The query would only fire (once) prior to rendering the view. For example, if you set the variable in the index action of the controller the query would

[Rails] Re: Rails equivalent of Delphi SetRange()

2010-07-11 Thread Mark Horrocks
Bb Serviss wrote: Many thanks to everyone who replied, this is a great forum. Delphi has been kind to me with the (visual component library) client data set which allows me to make a single query, then scope the remaining records in any way I see fit and loop through them, breaking out of the