-1

Following are 2 outputs from rails console:

1. Success

irb(main):038:0> Category.all
  Category Load (0.0ms)  SELECT "categories".* FROM "categories"
=> #<ActiveRecord::Relation [#<Category id: 1, name: "tutorials", created_at: "2016-05-14 18:44:38", updated_at: "2016-05-14 18:44:38">, #<Category id: 2, name: "news", created_at: "2016-05-14 18:44:38", updated_at: "2016-05-14 18:44:38">, #<Category id: 3, name: "design", created_at: "2016-05-14 18:44:38", updated_at: "2016-05-14 18:44:38">]>

2. Failure

irb(main):039:0> Category.find(:all)
  Category Load (0.0ms)  SELECT  "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT 1  [["id", nil]]
ActiveRecord::RecordNotFound: Couldn't find Category with 'id'=all
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/relation/finder_methods.rb:324:in `raise_record_not_found_exception!'
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/relation/finder_methods.rb:444:in `find_one'
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/relation/finder_methods.rb:423:in `find_with_ids'
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/relation/finder_methods.rb:71:in `find'
        from h:in `find'
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.3/lib/active_record/core.rb:130:in `find'
        from (irb):39
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start'
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from h:/rails/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'
irb(main):040:0>
Anthony E
  • 11,072
  • 2
  • 24
  • 44
Xenonius
  • 19
  • 2
  • Which Rails version are you using? – Pavan May 15 '16 at 10:00
  • 1
    That style was deprecated in 4.0 and removed in 4.1 as you Are on 4.2 it doesn't work anymore. If you need it you can. Use https://github.com/rails/activerecord-deprecated_finders but if you are writing new code you should use the new style as that gem won't work with 5 – Doon May 15 '16 at 10:04

1 Answers1

1

The find(:all) syntax was removed in Rails 4. You can use Category.all to get the same result.

Anthony E
  • 11,072
  • 2
  • 24
  • 44