In my app, when I go to localhost:3000/users/3 I get a
ActiveRecord::RecordNotFound at /users/3
But, when I go to my console and do u = User.find(3) I see this:
> u = User.find(3)
User Load (31.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 3]]
=> #<User id: 3, email: "abc3@test.com", encrypted_password: "$2a$10$x9iFcz1kooaQD1P9zFl/jOqwjC9veK6cCEP6zF/mtTMr...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2012-12-13 19:27:34", updated_at: "2012-12-13 19:27:34", name: "Third User">
Is it possible that it is being pulled from a different database, even though I didn’t specify any different db?
For what it’s worth, everything was working fine until I wanted to reset my db and re-run my seeds.rb….so I recently did:
rake db:reset and that did exactly what I wanted it to do, which was:
$ rake db:reset
-- create_table("roles", {:force=>true})
-> 0.0857s
-- add_index("roles", ["name", "resource_type", "resource_id"], {:name=>"index_roles_on_name_and_resource_type_and_resource_id"})
-> 0.0028s
-- add_index("roles", ["name"], {:name=>"index_roles_on_name"})
-> 0.0028s
-- create_table("users", {:force=>true})
-> 0.0899s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
-> 0.0045s
-- add_index("users", ["reset_password_token"], {:name=>"index_users_on_reset_password_token", :unique=>true})
-> 0.0061s
-- create_table("users_roles", {:id=>false, :force=>true})
-> 0.0663s
-- add_index("users_roles", ["user_id", "role_id"], {:name=>"index_users_roles_on_user_id_and_role_id"})
-> 0.0088s
-- initialize_schema_migrations_table()
-> 0.0136s
-- assume_migrated_upto_version(20121210211049, ["/my_app/db/migrate"])
-> 0.0358s
CREATING ROLES
SETTING UP DEFAULT USER LOGIN
New user created: First User
New user created: Second User
New user created: Third User
New user created: Fourth User
What could be causing this?
You need to restart your application.
After a reset, the old DB was dropped, and a new one created. Your app need to be restarted to match the new DB, caches, etc. 😉