Ruby on Rails Friday, July 30, 2010

crashbangboom wrote:
> I'm new to rails and am trying to get an understanding on some of the
> language usage...I have a mysql database with a table of data...I want
> to retrieve the last record in that table without sending it an 'id'
> or anything

Last by what definition? SQL databases return records in unpredictable
order unless you specify ORDER BY.

> ...I've tried the following:
>
> def get_last_net_vol
> @prevticket = Tankticket.find(:last)
> last_net_vol = @prevticket.net_vol
> return last_net_vol
> end
>
> This fails with:
>
> Couldn't find Tankticket with ID=last
[...]
> I'm running an old dual proc mac G4 with os x 10.5.8...ruby version
> 1.8.6...gem version 1.0.1...rails version 1.2.6

Perhaps find(:last) didn't exist in Rails 1.2.6. Even if it did, it's
pretty meaningless without :order, and useless with :order -- it would
be more efficient to sort the other way and use :first.

>
> I know I should update to the later version of rails and gem...

Yes, you certainly should.

> I have
> tried but the standard methods to do so fail with
> (Gem:RemoteSourceException) HTTP Response 301 fetching
> http://gems.rubyforge.org/yaml)...

What "standard methods"? What gave you this error?

> I guess I could install it the hard
> way but I don't want to chance compromising my current running
> install...!

Don't be afraid, just install the upgrade. Either use "gem update
--system" (which has worked for me on Leopard) or download a new version
of gem.

>
> Any light shed will be greatly appreciated...!

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment