字节笔记本

2026年2月22日

Homeland:基于 Ruby on Rails 的开源论坛社区系统

本文介绍 Homeland,一个基于 Ruby on Rails 开发的开源论坛/社区系统。该项目源自国内知名的 Ruby 开发者社区 Ruby China,经过多年实战打磨,已成为搭建垂直社区网站的优秀解决方案。

项目简介

Homeland 是一个功能完善的开源论坛/社区网站系统,由 Ruby China 团队开发维护。Ruby China 作为国内最活跃的 Ruby 开发者社区之一,其开源的 Homeland 系统凝聚了多年社区运营的技术经验。

截至目前,该项目在 GitHub 上已获得 3.9k+ Stars1.2k+ Forks,是 Ruby 生态中最受欢迎的社区系统之一。

核心特性

  • 完整的论坛功能:话题发布、回复、点赞、收藏、关注等完整社区交互
  • 用户系统:基于 Devise 的完整用户认证,支持邮箱验证、密码找回
  • 后台管理:功能完善的管理后台,支持内容审核、用户管理、数据统计
  • 插件扩展:支持插件机制,可灵活扩展功能
  • 响应式设计:基于 Bootstrap 5 和 TailwindCSS 的现代化界面
  • SEO 友好:完善的 SEO 支持,利于搜索引擎收录
  • Docker 部署:支持 Docker 和 Docker Compose 一键部署

技术栈

技术版本用途
Ruby3.4+编程语言
Rails8.0Web 框架
PostgreSQL14+主数据库
Redis6+缓存、队列
Bootstrap5.xUI 组件
TailwindCSS3.x样式框架
Shakapacker8.x前端构建
Elasticsearch7.x全文搜索(可选)

安装指南

前置要求

  • Docker 20.10+
  • Docker Compose 2.0+
  • 2GB 以上可用内存

Docker 部署(推荐)

bash
# 1. 克隆仓库
git clone https://github.com/ruby-china/homeland.git
cd homeland

# 2. 复制环境配置文件
cp .env.example .env

# 3. 启动服务
docker-compose up -d

# 4. 初始化数据库
docker-compose exec web bundle exec rails db:create db:migrate

# 5. 创建管理员账户
docker-compose exec web bundle exec rails console
# 在控制台执行:User.create!(login: 'admin', email: 'admin@example.com', password: 'password', name: '管理员')

开发环境搭建

bash
# 1. 克隆仓库
git clone https://github.com/ruby-china/homeland.git
cd homeland

# 2. 安装依赖
bundle install
yarn install

# 3. 配置数据库
# 编辑 config/database.yml 配置 PostgreSQL 连接

# 4. 创建数据库
rails db:create db:migrate

# 5. 启动开发服务器
./bin/dev

使用示例

基础配置

编辑 .env 文件配置站点信息:

bash
# 站点配置
APP_NAME=我的社区
DOMAIN=community.example.com

# 邮件配置
SMTP_ADDRESS=smtp.example.com
SMTP_PORT=587
SMTP_USER_NAME=noreply@example.com
SMTP_PASSWORD=your_password

# 存储配置(支持本地、阿里云 OSS、AWS S3)
UPLOAD_PROVIDER=aliyun
UPLOAD_ALIYUN_BUCKET=your-bucket
UPLOAD_ALIYUN_ENDPOINT=oss-cn-hangzhou.aliyuncs.com

插件开发

Homeland 支持插件扩展,示例插件结构:

ruby
# plugins/my_plugin/lib/my_plugin.rb
module MyPlugin
  class Engine < ::Rails::Engine
    isolate_namespace MyPlugin
  end
end

# 在 Gemfile 中添加
# gem 'my_plugin', path: 'plugins/my_plugin'

系统架构

text
┌─────────────────────────────────────────┐
│              Nginx/SSL                  │
└─────────────┬───────────────────────────┘
              │
┌─────────────▼───────────────────────────┐
│           Homeland App                  │
│  ┌─────────┐ ┌─────────┐ ┌──────────┐  │
│  │ Topics  │ │ Users   │ │ Replies  │  │
│  └─────────┘ └─────────┘ └──────────┘  │
│  ┌─────────┐ ┌─────────┐ ┌──────────┐  │
│  │ Admin   │ │ Search  │ │ Plugins  │  │
│  └─────────┘ └─────────┘ └──────────┘  │
└─────────────┬───────────────────────────┘
              │
    ┌─────────┼─────────┐
    ▼         ▼         ▼
┌───────┐ ┌───────┐ ┌─────────┐
│PostgreSQL│ │ Redis │ │ElasticSearch│
└───────┘ └───────┘ └─────────┘

相关资源

许可证

Homeland 基于 MIT 许可证开源,可自由用于商业和非商业项目。

分享: