Skip to content

Commit 8e9d451

Browse files
authored
Update README.md
1 parent 65fff41 commit 8e9d451

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

RoR/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ rails c # or rails console
2727
- Test model associations
2828
- Execute arbitrary Ruby code in your app's environment
2929

30+
```bash
31+
rails c
32+
user = User.new # Create a new User
33+
user.name = "Test User" # Set the name of the User
34+
user.save # Save the User to the database
35+
user.id # Get the ID of the User
36+
user.auth_token # Get the auth_token of the User
37+
user.errors # Get the errors of the User
38+
user.errors.full_messages # Get the full messages of the errors
39+
user.destroy # Destroy the User
40+
41+
42+
User.all # Get all Users
43+
User.first # Get the first User
44+
User.last # Get the last User
45+
User.count # Get the number of Users
46+
User.find(1) # Get the User with ID 1
47+
User.find_by(name: "Test User") # Get the User with name "Test User"
48+
User.take # Get a random User
49+
```
50+
3051
### Rails Logger
3152

3253
```ruby
@@ -56,11 +77,14 @@ Other useful database commands:
5677
```bash
5778
rails db:migrate # Run pending migrations
5879
rails db:rollback # Rollback last migration
80+
rails db:rollback STEP=5 # Rollback last 5 migrations
81+
rails db:migrate:down VERSION=VERSION_NUMBER # Rollback to a specific version
5982
rails db:reset # Drop & recreate database
6083
rails db:setup # Create database, load schema, and initialize with seed data
6184
rails db:drop db:create db:migrate # Reset database by dropping, creating, and running migrations
6285
ActiveRecord::Base.connection.tables # List all database tables
6386
ActiveRecord::Base.connection.columns('users').map(&:name) # List all column names of the 'users' table
87+
6488
```
6589

6690
## Code Quality Tools

0 commit comments

Comments
 (0)