-
Rails new with specific database
- rails new myapp --database=postgresql
- rails new myapp --database=mysql
- rails new myapp --database=sqlite3
-
API-only application
- rails new myapp --api
-
Minimal application without default gems
- rails new myapp --minimal
-
Rails 7+ with specific frontend configurations
- rails new myapp --css tailwind
- rails new myapp --css bootstrap
- rails new myapp --css bulma
- rails new myapp --javascript esbuild
- rails new myapp --javascript webpack
- rails new myapp --javascript importmap
-
Skip specific components
- rails new myapp --skip-test
- rails new myapp --skip-system-test
- rails new myapp --skip-active-storage
- rails new myapp --skip-action-mailbox
- rails new myapp --skip-action-text
-
Create database
- rails db:create
-
Run all pending migrations
- rails db:migrate
-
Rollback last migration
- rails db:rollback STEP=1
-
Rollback Version
- rails db:migrate:down VERSION=2022070100
-
Reset database (drop, create, migrate)
- rails db:reset
-
Load seed data
- rails db:seed
-
Drop database
- rails db:drop
-
Advanced Database Commands
- rails db:migrate:status # Check migration status
- rails db:version # Show current schema version
- rails db:schema:load # Load schema.rb
- rails db:structure:load # Load structure.sql
- rails db:setup # Create, load schema, and seed
- rails db:prepare # Prepare test database
- rails db:environment:set RAILS_ENV=production # Set environment
-
Database Maintenance
- rails db:schema:cache:clear # Clear schema cache
- rails db:schema:cache:dump # Create schema cache
- rails db:migrate:down VERSION=20230101000000 # Revert specific migration
- rails db:migrate:up VERSION=20230101000000 # Run specific migration
-
Generate model with attributes
- rails generate model User name:string email:string:uniq age:integer
-
Generate model with references
- rails generate model Comment content:text user:references post:references
-
Generate model with validations
- rails generate model Product name:string{30} price:decimal{10,2}
-
Advanced Model Generation
- rails generate model User admin:boolean default:false
- rails generate model Article slug:string:uniq title:string{100} body:text published_at:datetime
- rails generate model Profile user:belongs_to bio:text social_links:json
- rails generate model Category name:string position:integer:index
-
Generate controller with actions
- rails generate controller Users index show create update destroy
-
Generate API controller
- rails generate controller api/v1/Users index show --skip-template-engine
-
Generate controller with specific namespace
- rails generate controller Admin::Dashboard index
-
Additional Controller Options
- rails generate controller Posts --skip-routes
- rails generate controller Comments --skip-helper
- rails generate controller Admin::Products --skip-assets
- rails generate controller Api::V2::Users --skip-template-engine --api
-
Generate mailer
- rails generate mailer UserMailer welcome_email password_reset
-
Generate job
- rails generate job process_payment
- rails generate job send_notifications --queue urgent
-
Generate channel
- rails generate channel room speak
-
Generate serializer
- rails generate serializer user name email role
-
Generate stimulus controller
- rails generate stimulus form_validation
-
Run all tests
- rails test
-
Run specific tests
- rails test test/models/user_test.rb
-
Performance Tests
- rails generate performance_test browsing
- rails test:performance # Run performance tests
-
Parallel Testing
- rails test:parallel # Run tests in parallel
- rails test:prepare # Prepare parallel test database
-
Server Commands
- rails server -p 4000 # Run on specific port
- rails server -b 0.0.0.0 # Bind to all interfaces
- rails server -e production # Run in specific environment
- rails server -d # Run as daemon
-
Console Variations
- rails console --sandbox # Run console in sandbox mode
- rails console -e production # Production console
- rails console test # Test environment console
-
Debugging and Information
- rails stats # Code statistics
- rails notes # Show TODO/FIXME/OPTIMIZE comments
- rails middleware # Show middleware stack
- rails runner 'puts User.count' # Run Ruby code
-
Routes Information
- rails routes -g users # Show routes matching pattern
- rails routes -c Users # Show routes for controller
- rails routes --expanded # Display routes in expanded format
-
Asset Pipeline Commands
- rails assets:precompile # Compile assets
- rails assets:clean # Remove old compiled assets
- rails assets:clobber # Remove compiled assets
- rails assets:environment # Load asset environment
- rails assets:precompile:all # Compile all assets
-
Webpacker Specific (if using Webpacker)
- rails webpacker:install # Install Webpacker
- rails webpacker:compile # Compile JavaScript packs
- rails webpacker:clean # Clean old compiled packs
- rails webpacker:clobber # Remove compiled packs
-
Production Setup
- rails credentials:edit --environment production
- rails db:migrate RAILS_ENV=production
- rails assets:precompile RAILS_ENV=production
-
Secret Management
- rails secret # Generate secret key
- rails credentials:show # Show credentials
- rails encrypted:edit config/master.key # Edit master key
-
Cache Management
- rails dev:cache # Toggle development caching
- rails tmp:cache:clear # Clear tmp cache
- rails tmp:clear # Clear all tmp files
-
Hotwire/Turbo Installation
- rails turbo:install
- rails turbo:install:redis
-
Stimulus Installation
- rails stimulus:install
-
Import Map Commands
- bin/importmap pin @hotwired/turbo-rails
- bin/importmap pin @hotwired/stimulus
- bin/importmap pin lodash --download
- bin/importmap json
-
CSS Processing
- rails css:install:tailwind
- rails css:install:bootstrap
- rails css:install:postcss
- rails css:install:sass
-
Check routes
- rails routes | grep users
Last active
March 31, 2025 18:29
-
-
Save rafaelfnaves/8fe82c0a3ff10dd88b09bdab6cdd6a49 to your computer and use it in GitHub Desktop.
Really Essential Rails Commands
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment