Ruby on Rails 本地开发指南
使用 Rails 在 localhost:3000 运行 Ruby Web 应用,内置 Puma 服务器与 Active Record。
Ruby on Rails 是经典全栈 Web 框架,约定优于配置。本地开发使用 Puma,默认 **http://localhost:3000**。
快速开始
rails new myapp
cd myapp
bin/rails server
# 或 bin/dev(Rails 7+ 含 JS/CSS 构建)浏览器打开 **http://localhost:3000**。
指定端口
bin/rails server -p 3001数据库
开发环境默认 SQLite(db/development.sqlite3),无需额外服务。
使用 PostgreSQL:
# config/database.yml
development:
adapter: postgresql
host: localhost
port: 5432
database: myapp_developmentbin/rails db:create db:migrate常用命令
bin/rails console # REPL
bin/rails routes # 路由表
bin/rails db:migrate与 localhost 相关配置
config.hosts 在开发环境通常允许 localhost;若通过自定义域名(如 lvh.me)访问,需在 development.rb 放行。
常见问题
3000 端口占用
改 -p 或结束其他 Node/Rails 进程。
Bundler gem 安装失败
确认 Ruby 版本与 Gemfile 一致;bundle install。
小结
Rails 本地开发运行 bin/rails server,访问 **http://localhost:3000**,SQLite 零配置即可起步。