hi
i have just upgraded rails to the most recent version, and find(:last)
is still not working!
any ideas?
heres the code in my controller:
@testrun = Testrun.find(:last)
and heres the code in the view for test purposes:
<%= "#{@testrun.id}" -%>
and heres the error:
ActiveRecord::RecordNotFound in TestrunController#run
Couldn't find Testrun with ID=last
when i use @testrun = Testrun.find(:first), it works completely fine!
however i need to use last, tried a workaround @testrun =
Testrun.find_by_sql("select max(id) from testruns"), but this gives a
weird number ("29677700"), and not 16 which is the highest id in the
testruns table!
any help would be most appreciated!
thanks in advance!
on 19.08.2008 13:57
on 19.08.2008 14:04
Is this in an existing app? If so, did you change the Rails version used in environment.rb and then run rake rails:update to complete the update? Anyway, to get you moving in the meantime, just do what :last does... @last_run = Testrun.find :first, :order => "id desc" On Tue, Aug 19, 2008 at 6:57 AM, Brad Symons <
on 19.08.2008 14:06
Try this: @testrun = Testrun.find(:all).last.id
on 19.08.2008 14:09
> Is this in an existing app? If so, did you change the Rails version used > in > environment.rb and then run rake rails:update to complete the update? yes updated environment.tb with new version no, didnt run rake rails:update -> now done it and command line returned quickly so not sure if any effect has taken place running via aptana, so would i need to restart aptana too? > @last_run = Testrun.find :first, :order => "id desc" thanks, will give this a try. much simpler with the :last option though! cheers.!
on 19.08.2008 14:15
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION ->updated ran rake rails:update -> all looks good C:\InstantRails\rails_apps\tpt>rake rails:update --trace (in C:/InstantRails/rails_apps/tpt) ** Invoke rails:update (first_time) ** Invoke rails:update:scripts (first_time) ** Execute rails:update:scripts ** Invoke rails:update:javascripts (first_time) ** Execute rails:update:javascripts ** Invoke rails:update:configs (first_time) ** Execute rails:update:configs ** Execute rails:update restart aptana, and still get the same problems??
on 19.08.2008 14:19
Vidya Ramachandren wrote: > Try this: > @testrun = Testrun.find(:all).last.id thanks, that works! but why doesnt (:last) work, is it a bug or something? do you have any tips how to make a find_by_sql to work as well? the syntax? thanks again!
on 19.08.2008 14:19
Indeed, or you have an old version frozen in your vendor folder. Do script/console and see what it says. liquid-snake:~/10-FW/RAILS/thinx peter$ script/console Loading development environment (Rails 2.1.0) >> Company.find(:last) => #<Company id: 3, name: "Suez", short_name: "CC", active: nil, language_code: 2, created_at: "2008-08-14 13:32:09", updated_at: "2008-08-14 13:32:09"> >> Company.last => #<Company id: 3, name: "Suez", short_name: "CC", active: nil, language_code: 2, created_at: "2008-08-14 13:32:09", updated_at: "2008-08-14 13:32:09"> On 19 Aug 2008, at 14:02, Brian Hogan wrote: > > and heres the code in the view for test purposes: > <%= "#{@testrun.id}" -%> Best regards Peter De Berdt
on 19.08.2008 14:24
hi peter where do i run the script/console command, via dos? and what exactly am i looking for? how can i determine if an old version is hanging around? more information needed, im a newbie to rails. thanks
on 19.08.2008 14:26
On 19 Aug 2008, at 12:57, Brad Symons wrote: > > Couldn't find Testrun with ID=last > > when i use @testrun = Testrun.find(:first), it works completely fine! > > however i need to use last, tried a workaround @testrun = > Testrun.find_by_sql("select max(id) from testruns"), but this gives a > weird number ("29677700"), and not 16 which is the highest id in the > testruns table! > That returns an array of objects, so when you called id on it you were getting the id of the array, not the id of the record. You don't need find_by_sql for this: Testrun.max(:id) should do the trick. It really does sound as though you're just running 2.0.2. Did you check the output of script/console as suggested. Do you have any plugins that might be overriding find ? Fred
on 19.08.2008 14:27
On 19 Aug 2008, at 13:24, Brad Symons wrote: > > hi peter > > where do i run the script/console command, via dos? and what exactly > am > i looking for? how can i determine if an old version is hanging > around? > from your app's folder run ruby script/console it outputs the version of rails it's running. Fred
on 19.08.2008 14:31
On 19 Aug 2008, at 14:06, Vidya Ramachandren wrote: > Try this: > @testrun = Testrun.find(:all).last.id That's about the most horrible way of doing it: load the complete recordset into memory, then take the last one and get the id. The best way is to sort by id DESC and then take the first one. That's what .last does anyway. And by the looks of it, you're still running Rails 2.0.2: > RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION - > >updated The :last and named_scope feature was introduced in Rails 2.1, which is the latest version, not Rails 2.0.2. Best regards Peter De Berdt
on 19.08.2008 14:51
Peter's correct. You're trying to use a 2.0.2 Rails copy when you should be using a 2.1
on 19.08.2008 15:02
find(:last) doesn't work for me in 2.0.2 it works fine in 2.1 find_by_sql works fine the way described in the api. On Aug 19, 7:19 am, Brad Symons <rails-mailing-l...@andreas-s.net>
on 19.08.2008 15:04
> You're trying to use a 2.0.2 Rails copy when you should be using a 2.1
yes im running rails 2.0.2, in fact this is the most recent build
packaged with instantrails 2.0.
can anyone recommend me to a good site for installing ruby/rails outside
of instant rails because ive tried a few times, and it seems never to
run smoothly, usually the RUBY_ENV problems, not picking up the right
things, and then GEM issues to.
??
on 19.08.2008 15:09
gem install update rails doesn't work? On Aug 19, 8:04 am, Brad Symons <rails-mailing-l...@andreas-s.net>
on 19.08.2008 15:12
In 2.0.2, the only method given above which works is: @testrun = Testrun.find(:all).last.id @testrun = Testrun.find :first, :order => "id desc >> gives "#" in the view as the id @testrun = Testrun.max(:id) >> gives undefined method `max' for #<Class:0x39d24e0> so the nasty method in 2.0.2 seems the be the only way forward, thanks, but until i can run rails outside of instantrails(which i believe is not being supported or developed anymore) i will have to stick with this. thanks for all your help. although still not sure the find_by_sql will work, as mentioned above, the 2357423 it returns is the array location or whatever, how do i then translate to give me the 18(the last record with the highest id) in the db. using the find_by_sql("select max(id) from testruns)???
on 19.08.2008 15:15
Jorg Lueke wrote:
> gem install update rails doesn't work?
i cant run it, as my company has a download firewall, so the aptana auto
updater cant get any access to the outside world to update.
and i tried to install the gem manually, but i had a bit of trouble, via
the zip, where and how do i do that?
i extracted it into the gems folder, but for some reason it wasnt being
picked up!
thanks for your help!
on 19.08.2008 15:16
Did you try gem update rails and updating your version in any existing environment.rb? On Aug 19, 8:04 am, Brad Symons <rails-mailing-l...@andreas-s.net>
on 19.08.2008 15:18
On 19 Aug 2008, at 15:04, Brad Symons wrote:
> things, and then GEM issues to
Make it easy on yourself and make either a virtual machine running
linux or make a linux/windows dual boot (Windows for gaming and adware/
virus fun, Linux for real productivity). I would recommend Ubuntu if
you're not familiar with Linux, because the latest version is just
such a smooth install (better than a Winblows install even, not too
hard, but you get the point). You'll have far less problems with gems
too.
Best regards
Peter De Berdt
on 19.08.2008 15:22
On 19 Aug 2008, at 14:12, Brad Symons wrote: > > In 2.0.2, the only method given above which works is: > > @testrun = Testrun.find(:all).last.id > > @testrun = Testrun.find :first, :order => "id desc >>> gives "#" in the view as the id that's because @testrun is an instance of Testrun, not an integer @testrun = Testrun.find( :first, :order => "id desc").id would work (although you'll get an error there if there are no testruns) >>> > > @testrun = Testrun.max(:id) >>> gives undefined method `max' for #<Class:0x39d24e0> > D'oh the method is maximum not max. > then > translate to give me the 18(the last record with the highest id) in > the > db. > > using the find_by_sql("select max(id) from testruns)??? > you need to look at the first element of that array. Fred
on 19.08.2008 15:32
On 19 Aug 2008, at 14:15, Brad Symons wrote: > the zip, where and how do i do that? > You can download the actual .gem file and install that ie gem install something.gem Fred
on 19.08.2008 15:42
> You can download the actual .gem file and install that ie > > gem install something.gem yes i have done that before, but as im running instantrails, im sure it game errors, something that gem install is not a valid command, when being run in a dos screen. thanks for your help for now, as i get more visibility with rails, i think i will be able to cope better with the unforseen!! thanks alot guys! cheers!
on 19.08.2008 15:48
On 19 Aug 2008, at 14:42, Brad Symons wrote: > >> You can download the actual .gem file and install that ie >> >> gem install something.gem > > yes i have done that before, but as im running instantrails, im sure > it > game errors, something that gem install is not a valid command, when > being run in a dos screen. you might need to cd to wherever instant rails keeps the gem command. Fred
on 19.08.2008 16:49
thanks fred! youve helped me alot! once im a guru, perhaps i can help someone in here too! im swatting it all now! thanks again !