I can''t get find(:all) to work. The facts: - debian - rails (versions listed below) I have a controller called "activity" (activity_controller.rb). I have a model called ''Play'' (play.rb). activity_controller.rb is: class ActivityController < ApplicationController def index @plays = Play.find( :all, :limit=> 20 ) end end When I punch the activity page I get: ActiveRecord::RecordNotFound in Activity#index Couldn''t find Play with ID=all app/controllers/activity_controller.rb:6:in `index'' I''m trying to find all, not a specific ID (well, the first 20) I hope someone will point out the mistake I''ve made. In addition, I''m open to any suggestions for debugging this type of problem in the future. Thanks, -Kelly *** LOCAL GEMS *** actionmailer (0.9.1) Service layer for easy email delivery and testing. actionpack (1.8.1) Web-flow and rendering framework putting the VC in MVC. actionwebservice (0.7.1) Web service support for Action Pack. activerecord (1.10.1) Implements the ActiveRecord pattern for ORM. activesupport (1.0.4) Support and utility classes used by the Rails framework. login_generator (1.1.0) [Rails] Login generator. rails (0.12.1) Web-application framework with template engine, control-flow layer, and ORM. rake (0.5.3) Ruby based make-like utility. sources (0.0.1) This package provides download sources for remote gem installation _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Kelly Felkins wrote:> I can''t get find(:all) to work. > > The facts: > > * debian > * rails (versions listed below) > > I have a controller called "activity" (activity_controller.rb). I have > a model called ''Play'' (play.rb). > > activity_controller.rb is: > class ActivityController < ApplicationController > > def index > @plays = Play.find( :all, :limit=> 20 ) > end > > end > > When I punch the activity page I get: > > > ActiveRecord::RecordNotFound in Activity#index > > Couldn''t find Play with ID=all > >|app/controllers/activity_controller.rb:6:in `index'' >| > > I''m trying to find all, not a specific ID (well, the first 20) > > I hope someone will point out the mistake I''ve made. In addition, I''m > open to any suggestions for debugging this type of problem in the future. > > Thanks, > -Kelly > >|| > > *** LOCAL GEMS *** > > actionmailer (0.9.1) > Service layer for easy email delivery and testing. > > actionpack (1.8.1) > Web-flow and rendering framework putting the VC in MVC. > > actionwebservice (0.7.1) > Web service support for Action Pack. > > activerecord (1.10.1) > Implements the ActiveRecord pattern for ORM. > > activesupport (1.0.4) > Support and utility classes used by the Rails framework. > > login_generator (1.1.0) > [Rails] Login generator. > > rails (0.12.1) > Web-application framework with template engine, control-flow layer, > and ORM. > > rake (0.5.3) > Ruby based make-like utility. > > sources (0.0.1) > This package provides download sources for remote gem installation > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >Try @plays = Play.find_all(:limit=> 20 ) Regards // JoNtE
On 26.4.2005, at 09:17, Jonas Montonen wrote:> Try > @plays = Play.find_all(:limit=> 20 )Well, actually Play.find(:all, :limit => 20) is the new recommended syntax. Find_all should still work, but you can''t assign limits to it like you do above. Kelly, for me your exact syntax works fine. You can try to play around with irb (type "script/console development" in command line to start your development environment) and see if you can get the call working. But like said, for me "@models = Model.find( :all, :limit => 20)" works just fine so I don''t know what''s causing your problems. //jarkko> > Regards // JoNtE > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hmmm. I''m a little suspicious of my rails install on debian, which is why I listed the gems versions. Most things seem to be working fine but I had a bit of trouble getting rails installed initially. Thanks for your note. -Kelly On 4/25/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > > On 26.4.2005, at 09:17, Jonas Montonen wrote: > > Try > > @plays = Play.find_all(:limit=> 20 ) > > Well, actually Play.find(:all, :limit => 20) is the new recommended > syntax. Find_all should still work, but you can''t assign limits to it > like you do above. > > Kelly, for me your exact syntax works fine. You can try to play around > with irb (type "script/console development" in command line to start > your development environment) and see if you can get the call working. > But like said, for me "@models = Model.find( :all, :limit => 20)" works > just fine so I don''t know what''s causing your problems. > > //jarkko > > > > > Regards // JoNtE > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> I can''t get find(:all) to work. > > The facts: > > - debian > - rails (versions listed below) > > I have a controller called "activity" (activity_controller.rb). I have > a > model called ''Play'' (play.rb). >Try adding model :play to your controller named ActivityController: class ActivityController < ApplicationController model :play def index @plays = Play.find( :all, :limit=> 20 ) end end
Thanks for the suggestion, but no joy. Any other ideas? I hope that there is someone that knows the rails code well enough to simply recognize the error and can say something like "rails can''t find your dinglefarb - check your load path." or "rails is trying to use the sql-dohickey - switch to the mysql-dohickey" Still: ActiveRecord::StatementInvalid in Activity#index Unknown column ''limit20'' in ''where clause'': SELECT * FROM plays WHERE limit20 app/controllers/activity_controller.rb:8:in `index'' On 4/26/05, Andrew Otwell <andrew-uQjPo4GTFqgS+FvcfC7Uqw@public.gmane.org> wrote:> > > > I can''t get find(:all) to work. > > > > The facts: > > > > - debian > > - rails (versions listed below) > > > > I have a controller called "activity" (activity_controller.rb). I have > > a > > model called ''Play'' (play.rb). > > > > Try adding model :play to your controller named ActivityController: > > class ActivityController < ApplicationController > model :play > > def index > @plays = Play.find( :all, :limit=> 20 ) > end > > end > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> ActiveRecord::StatementInvalid in Activity#index > > Unknown column ''limit20'' in ''where clause'': SELECT * FROM plays WHERE > limit20 app/controllers/activity_controller.rb:8:in `index''Are you passing a hash to your conditions? I believe if you pass a hash like { :limit => 20 }, it joins them like ''limit20''. At any rate, check line 8 of your activity_controller.rb and see how you''re calling Model.find. Should be something like: Model.find :all, :conditions => ''title = ?'', my_title, :limit => 20 If you''re still really new to ruby syntax, this works as well: Model.find(:all, { :conditions => ''title = ?'', my_title, :limit => 20 } ) Since #find takes 1 parameter followed by a hash, it assumes thats what you pass it, allowing you to leave out the parentheses and brackets. -- rick http://techno-weenie.net