🖥️ Rails Console


🚀 Start Console

bundle exec rails console
# or shorthand
bundle exec rails c


🔍 Explore Schema & Records

Task.column_names       # ["id", "title", "created_at", "updated_at"]
Task.count              # total rows in tasks table


➕ Create Records

Task.create(title: "First Task")


❌ Exit Console

exit


🔄 Reload

reload!                 # Reload app code
my_task.reload          # Reload object from DB

Works only on saved records.


🪄 Last Expression Shortcut

Task.find(1)
_                      # returns last evaluated value