# Ruby on Rails — Full-Stack Web Framework That Started It All > Ruby on Rails is a full-stack web framework optimized for programmer happiness. Convention over configuration, MVC architecture, ActiveRecord ORM, migrations, and scaffolding. Created by DHH in 2004 and still powering GitHub, Shopify, Basecamp, and Airbnb. ## Install Save in your project root: ## Quick Use ```bash # Install Ruby and Rails gem install rails rails new myapp --database=postgresql cd myapp rails db:create rails server # Visit http://localhost:3000 ``` Scaffold a resource: ```bash rails generate scaffold Asset repo:string stars:integer description:text rails db:migrate # Visit http://localhost:3000/assets # Full CRUD ready: index, show, new, create, edit, update, destroy ``` Model with validations: ```ruby # app/models/asset.rb class Asset < ApplicationRecord validates :repo, presence: true, uniqueness: true validates :stars, numericality: { greater_than_or_equal_to: 0 } scope :popular, -> { where("stars >= ?", 10000).order(stars: :desc) } end ``` ```ruby # Rails console rails console > Asset.create(repo: "react", stars: 230000) > Asset.popular.limit(5) > Asset.where("stars > ?", 100000).count ``` ## Intro Ruby on Rails (often just "Rails") is a full-stack web application framework written in Ruby. Created by David Heinemeier Hansson (DHH) while building Basecamp, open-sourced in 2004. Rails popularized Convention over Configuration (CoC) and Don"t Repeat Yourself (DRY) — ideas that influenced every web framework since. Powers GitHub, Shopify, Basecamp, Airbnb, Hulu, and many others. - **Repo**: https://github.com/rails/rails - **Stars**: 58K+ - **Language**: Ruby - **License**: MIT ## What Rails Does - **MVC** — Model, View, Controller architecture - **ActiveRecord** — ORM with migrations, validations, associations - **Scaffold** — one-command CRUD generation - **Routing** — RESTful resource routing - **Action View** — ERB/Haml templates - **Action Cable** — WebSocket framework - **Active Job** — background job abstraction - **Action Mailer** — email sending with templates - **Active Storage** — file uploads to S3/GCS/Azure - **Turbo + Stimulus** — Hotwire for HTML-over-the-wire - **Kamal** — deploy Rails anywhere with Docker - **Solid Queue/Cache/Cable** — database-backed infrastructure ## Architecture Full MVC with an opinionated project structure. Convention over Configuration means file names, directory layouts, and naming patterns determine behavior. Asset pipeline (Propshaft/Dartsass in Rails 7+) for CSS/JS. Rails 8 introduces Solid trifecta for database-backed queues, caches, and WebSockets. ## Self-Hosting ```bash # Production (Rails 8) KAMAL_REGISTRY_PASSWORD=xxx kamal setup kamal deploy # Traditional bundle exec puma -C config/puma.rb # Behind Nginx reverse proxy ``` ## Key Features - Convention over Configuration - ActiveRecord ORM - Scaffold generators - RESTful routing - Hotwire (Turbo + Stimulus) - Action Cable (WebSocket) - Active Job (background) - Active Storage (uploads) - Kamal deployer - Rails 8 Solid trifecta - Mature gem ecosystem ## Comparison | Framework | Language | Philosophy | Speed | |---|---|---|---| | Rails | Ruby | Convention > config | OK | | Django | Python | Batteries-included | OK | | Laravel | PHP | Elegant syntax | OK | | Phoenix | Elixir | Convention + speed | Fast | | Spring Boot | Java | Enterprise auto-config | OK | | Next.js | TypeScript | Full-stack React | Fast | ## 常见问题 FAQ **Q: Rails 性能?** A: Ruby 3.3 + YJIT 让 Rails 比 Ruby 2.x 快 3 倍。Shopify 全球百万商户在 Rails 上跑。性能瓶颈通常在数据库,不在框架。 **Q: Rails 7 vs 8?** A: Rails 8 推出 Solid Queue(DB-backed 队列,不需要 Redis)、Solid Cache、Solid Cable,简化部署。加上 Kamal deployer,目标是单人全栈开发者也能 deploy anywhere。 **Q: Hotwire 是什么?** A: Turbo(HTML-over-the-wire 取代 SPA)+ Stimulus(轻量 JS sprinkles)+ Strada(mobile bridge)。用 Rails 写全栈 app 不需要 React 或前后端分离。 ## 来源与致谢 Sources - Docs: https://guides.rubyonrails.org - GitHub: https://github.com/rails/rails - License: MIT --- Source: https://tokrepo.com/en/workflows/cc16545d-362e-11f1-9bc6-00163e2b0d79 Author: AI Open Source