Hi list, I''m new here, and have been doing my web dev with perl/mysql for many years. I''m just getting started with rails and have run into some questions about the scaffold code. The first thing I''m curious about has to do with the ''list'' pagination. Is it scalable to a table with thousands or hundreds of thousands of records? It''s not loading the whole list into memory is it? Second, after adding or editing, I''d like to do away with the ''show'' page for some tables and just go back to the list, and I''m not quite sure how to do that. Also, when going back to the list from an edit or add, I''d like the list page to have the latest item to be added/edited as the first item on the page, or at least to have the proper page displayed, while at least highlighting the record in some way. How can I accomplish that? Thanks for helping a noob. Regards, Rich -- Current Conditions in Des Moines, IA Few Clouds Temp 66.2F Winds out of the Southeast at 6mph Moderate Mist
Hi Rich, I''m still relatively a noob, but it''s surprising how fast this stuff can be picked up! Rich Duzenbury wrote:> The first thing I''m curious about has to do with the ''list'' pagination. > Is it scalable to a table with thousands or hundreds of thousands of > records? It''s not loading the whole list into memory is it?I''m afraid I have no idea about that one.> Second, after adding or editing, I''d like to do away with the ''show'' > page for some tables and just go back to the list, and I''m not quite > sure how to do that.In your controller, find the "update" function that looks like: def update @blah = Blah.find(params[:id]) if @blah.update_attributes(params[:blah]) flash[:notice] = ''Blah was successfully updated.'' redirect_to :action => ''show'', :id => @blah else render :action => ''edit'' end end Then change this line: redirect_to :action => ''show'', :id => @blah ... to... redirect_to :action => ''list''> Also, when going back to the list from an edit or add, I''d like the list > page to have the latest item to be added/edited as the first item on the > page, or at least to have the proper page displayed, while at least > highlighting the record in some way. How can I accomplish that?When listing, you can specify the order that the items appear in. In your controller, find the "list" function that looks like: def list @blah_pages, @blahs = paginate :blah, :per_page => 10 end ... and append this to the paginate line: order_by => ''updated_at'' Then, you''ll need to have a Timestamp field called "updated_at" in your database table, and the magic should happen automatically AFAIK. As I said, I''m still a noob, so I''m trying my hand at solving other people''s problems in order to get better myself. ;-) My first major Rails app (a car park booking system for a small international airport) is going really well so far, and is rapidly picking up pace! Stick with it, because when you start to get the hang of this stuff, it''s literally *AWESOME*. :-D If you don''t have the Rails book, it''s pretty essential reading... http://www.pragmaticprogrammer.com/titles/rails/ Also, the Ruby "Pickaxe" book is fantastic... http://www.pragmaticprogrammer.com/titles/ruby/ ... and an online version of the first edition (slightly out of date, but fine for a lot of things) is available here: http://www.rubycentral.com/book/ Cheers, ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
Dave Silvester wrote:> order_by => ''updated_at''Sorry, there was a typo there. That should have been (colon at start): :order_by => ''updated_at'' ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
On Mon, 2005-09-05 at 17:25 +0100, Dave Silvester wrote:> Hi Rich, > > I''m still relatively a noob, but it''s surprising how fast this stuff can be > picked up! > > Rich Duzenbury wrote: > > The first thing I''m curious about has to do with the ''list'' pagination. > > Is it scalable to a table with thousands or hundreds of thousands of > > records? It''s not loading the whole list into memory is it? > > I''m afraid I have no idea about that one. > > > Second, after adding or editing, I''d like to do away with the ''show'' > > page for some tables and just go back to the list, and I''m not quite > > sure how to do that. > > In your controller, find the "update" function that looks like: > > def update > @blah = Blah.find(params[:id]) > if @blah.update_attributes(params[:blah]) > flash[:notice] = ''Blah was successfully updated.'' > redirect_to :action => ''show'', :id => @blah > else > render :action => ''edit'' > end > end > > Then change this line: > > redirect_to :action => ''show'', :id => @blah > > ... to... > > redirect_to :action => ''list'' > > > Also, when going back to the list from an edit or add, I''d like the list > > page to have the latest item to be added/edited as the first item on the > > page, or at least to have the proper page displayed, while at least > > highlighting the record in some way. How can I accomplish that? > > When listing, you can specify the order that the items appear in. In your > controller, find the "list" function that looks like: > > def list > @blah_pages, @blahs = paginate :blah, :per_page => 10 > end > > ... and append this to the paginate line: > > order_by => ''updated_at'' > > Then, you''ll need to have a Timestamp field called "updated_at" in your > database table, and the magic should happen automatically AFAIK. > > As I said, I''m still a noob, so I''m trying my hand at solving other people''s > problems in order to get better myself. ;-) My first major Rails app (a car > park booking system for a small international airport) is going really well so > far, and is rapidly picking up pace! Stick with it, because when you start to > get the hang of this stuff, it''s literally *AWESOME*. :-D > > If you don''t have the Rails book, it''s pretty essential reading... > > http://www.pragmaticprogrammer.com/titles/rails/ > > Also, the Ruby "Pickaxe" book is fantastic... > > http://www.pragmaticprogrammer.com/titles/ruby/ > > ... and an online version of the first edition (slightly out of date, but fine > for a lot of things) is available here: > > http://www.rubycentral.com/book/ > > Cheers, > > ~Dave >Thanks Dave. Hopefully someone else will know how scalable the list / pagination thingy is. At first, I liked your solution to the paginate problem, but in retrospect, I think it will be confusing to the user to see the records ''out of order''. I''d like for the records to continue to be shown in the primary key order. Say a user is editing a record that initially appeared on page three of the list. Following the edit of the record, the user should be redirected back to the list, to whatever page the record appears on. Currently, the list just dumps back to page one. This will be annoying to the user. Surely, there is some method for showing other than page 1? Thanks. Regards, Rich -- Current Conditions in Des Moines, IA Few Clouds Temp 73.4F Winds out of the Southwest at 12mph
On Mon, 2005-09-05 at 17:35 +0100, Dave Silvester wrote:> Dave Silvester wrote: > > order_by => ''updated_at'' > > Sorry, there was a typo there. That should have been (colon at start): > > :order_by => ''updated_at'' > > ~Dave >Hmm, there seems to be a problem with this. This orders by the updated_at in ascending order. Or, oldest first. What is the syntax for ''order by updated at in descending order''? Thanks. Regards, Rich -- Current Conditions in Des Moines, IA Scattered Clouds Temp 82.4F Winds out of the Southwest at 18mph
Rich Duzenbury said the following on 2005-09-06 13:32:> Hmm, there seems to be a problem with this. This orders by the > updated_at in ascending order. Or, oldest first. What is the syntax > for ''order by updated at in descending order''?:order_by => ''updated_at desc'' Remember that the text will be interpolated in the resulting SQL, so you can use any SQL expression your server accepts. Bye ! François
On Tue, 2005-09-06 at 13:43 -0400, François Beausoleil wrote:> > Rich Duzenbury said the following on 2005-09-06 13:32: > > Hmm, there seems to be a problem with this. This orders by the > > updated_at in ascending order. Or, oldest first. What is the syntax > > for ''order by updated at in descending order''? > > :order_by => ''updated_at desc'' > > Remember that the text will be interpolated in the resulting SQL, so you > can use any SQL expression your server accepts.Ahh, thanks François. I can''t yet ''remember'' anything about rails yet, since I am very new. Regards, Rich -- Current Conditions in Des Moines, IA Broken Clouds Temp 80.6F Winds out of the South at 8mph