There is something wrong is going on in my Rails console :
arup@linux-wzza:~/Rails/test_app> rails c
Loading development environment (Rails 4.1.1)
2.1.1 :001 > Order
=> Order (call 'Order.connection' to establish a connection)
2.1.1 :002 >
Every time I am starting my console, getting the same "Order (call
'Order.connection' to establish a connection)". After I am hitting the method
Order.connection. I am able to work on the model class(s). How can I make it
automatic, so that once I will open my console, I can start work with out
doing such manual connection establishment.
The message is a little misleading, but it’s normal. Starting with Rails 4, Rails lazy loads the database connection. In other words, it establishes the connection only when it first needs it. When you instantiate the class, it’s giving you a message that the connection is not yet established. Any method on the class (or an instance of the class) that requires a database call will automatically establish the connection, you don’t need to call Order.connection. For example, if you now write:
order = Order.find(1)
that will automatically create the connection.
If this isn’t the case and it isn’t behaving in this manner, please post all the messages you get as well as the code for your model.