I’m trying to make a simple logging application that just displays the
last few rows of information in the log. In order to do this, I am
trying to use the “:offset” option for find. However, I am not getting
the results I expect.
For testing purposes, the query is being run against a table (MySQL)
that contains 11 records. According to the RoR documentation, when I
use the :offset parameter as shown below, I expect to get back 6 records
instead of 11. Am I just not reading the documentation correctly?
# This should return all rows in the table after the fifth row
@transactions = Transaction.find(:all, :offset => 5 )
# Should show 6 if the total rows are 11
puts "TOTAL ROWS RETURNED IS: " + @transactions.size.to_s
I’m trying to make a simple logging application that just displays the
last few rows of information in the log. In order to do this, I am
trying to use the “:offset” option for find. However, I am not getting
the results I expect.
For testing purposes, the query is being run against a table (MySQL)
that contains 11 records. According to the RoR documentation, when I
use the :offset parameter as shown below, I expect to get back 6 records
instead of 11. Am I just not reading the documentation correctly?
# This should return all rows in the table after the fifth row
@transactions = Transaction.find(:all, :offset => 5 )
# Should show 6 if the total rows are 11
puts "TOTAL ROWS RETURNED IS: " + @transactions.size.to_s
Thanks in advance for any insight or help.
Doug
It appears MySQL also needs a “:limit” parameter specified in addition
to the “:offset” parameter. I have not tested this issue with
PostgreSQL or any other dbs but assume this could also apply in other
such cases.
I purchased the first edition of “Agile Web D. with Rails” some
time back and never had a time to get into it. I want to learn now but
I’ve seen there’s a second edition. Is the content in the first edition
still relevant, or are some parts of it “depreceated” or no longer
current? Should I get the second edition? What about “Rails Receipes”
as well?
:offset it dependent on :limit, in other words, if you don’t specify
:limit, :offset is basically ignored (look at the sql generated in
your log to see). this is because the offset is part of the limit
clause and is optional, however, the # of rows to limit is not
select * from table … [limit [offset,] rows]
so
select * from table … limit 10, 20
would select limit the number of returned rows to 20 starting at row 10
Rails Recipes is quite good too, but it is very much advanced
material for people comfortable with Rails. n00bs like me can’t
put much of it into practice, but theres a lot of nice stuff in there
I purchased the first edition of “Agile Web D. with Rails” some
time back and never had a time to get into it. I want to learn now but
I’ve seen there’s a second edition. Is the content in the first edition
still relevant, or are some parts of it “depreceated” or no longer
current? Should I get the second edition? What about “Rails Receipes”
as well?
I have the 1st edition and I don’t regret buying the 2nd edition at
all. It’s been well worth it, even as a beta book.
I purchased the first edition of “Agile Web D. with Rails” some
time back and never had a time to get into it. I want to learn now but
I’ve seen there’s a second edition. Is the content in the first edition
still relevant, or are some parts of it “depreceated” or no longer
current? Should I get the second edition?
AFIK there are no statements in 1st deprecrated with Rails 1.1.4.
Sure, 2nd edition have majors rewrite and additions, but you can start
learning with a recent rails setup and this book.
Big enhancements in 2nd are for medium level (web)developers (RJS
Templates, Migrations, Polymorphic associations), your 1st edition
cover unchanged basics for beginning, let’s go
I’m using last Rails 1.1.4 with 1st, just printed some chapters from
2nd PDF (Migrations) because I want use them, and I keep an eye on the
online API for new methods and minor changes.
What about “Rails Receipes” as well?
Good indeep rails programming techniques, a very good complement, and
more up to date with rails 1.1 than AWDWR, too few RJS for my taste.
Yeah, I started to teach myself Rails a week ago with the first edition
book, but found that certain aspects were a little behind the kind of
code I
was seeing in online tutorials, etc. (especially with regards to
database
migration, if you watch the “migrations” screencast you’ll be scratching
your head with the first ed.)…so I picked up the beta .pdf of the
second
edition, and am liking it much more. Just in the depot application,
some
things are implemented in a much cleaner way (more “Ruby-like” seems to
be
the parlance).
On the other hand, if you can’t wait to start coding, you can use the
first
edition for now, just check out a tutorial on migrations:
and use those instead of the DDL schemas used in the book. That seems
to be
the most important difference with regards to the example app (other
than
the second ed. gives some examples of AJAX integration). As for the
rest of
the book, I haven’t gotten there yet
I would still strongly recommend getting the second edition book when it
comes out (or getting the beta .pdf now.) I seem to recall that the
thing
is scheduled for release in September, so it’s not much of a wait.
A lot of the testing stuff in the 1st edition is deprecated now.
Especially the stuff related to instantiated fixtures.
That’s the biggest problem–they made that incompatible change after
the book went to press. The other stuff should work, but the new
Rails adds a lot of additional features (such as migrations and RJS)
they are pretty important.
The first edition still works in terms of writing viable code for
Rails applications…
I found the Recipes book to be very good depending on your Ruby
skillz. If you Ruby skillz needs some love David Black’s “Ruby for
Rails” is really good. But I have 2nd edition of the Agile book in
beta and I felt it was a worthy upgrade over the 1st edition.