Thursday, April 17, 2014

Rails console no database connection

Rails console no database connection

if this happens to you right after you load Rails 4 console:
rails c
User
 => User(no database connection)
It just means that ActiveRecord has not yet connected to the database and therefore does not know the column information. This is so that will not connect to DB unless needed to (speed improvements in Rails 4).
to connect just call
User.connection

# or

User.last
Rails 4