DDD Rails Sample 项目使用教程
1. 项目的目录结构及介绍
ddd-rails-sample/
├── app/
│ ├── layers/
│ ├── bin/
│ ├── config/
│ ├── db/
│ ├── lib/
│ ├── log/
│ ├── public/
│ ├── spec/
│ ├── tmp/
│ └── vendor/
├── env.development
├── env.test
├── .gitignore
├── .rspec
├── .ruby-gemset
├── .ruby-version
├── Gemfile
├── Gemfile.lock
├── LICENSE
├── README.md
├── Rakefile
└── config.ru
目录结构介绍
app/
: 包含应用程序的核心代码,如控制器、模型、视图等。layers/
: 应用层代码。bin/
: 可执行文件。config/
: 应用程序配置文件。db/
: 数据库相关文件。lib/
: 库文件。log/
: 日志文件。public/
: 公共文件,如图片、CSS、JavaScript等。spec/
: 测试文件。tmp/
: 临时文件。vendor/
: 第三方库文件。
env.development
: 开发环境配置。env.test
: 测试环境配置。.gitignore
: Git忽略文件配置。.rspec
: RSpec配置文件。.ruby-gemset
: Ruby gemset配置。.ruby-version
: Ruby版本配置。Gemfile
: 依赖管理文件。Gemfile.lock
: 依赖锁定文件。LICENSE
: 许可证文件。README.md
: 项目说明文件。Rakefile
: Rake任务配置文件。config.ru
: Rack服务器配置文件。
2. 项目的启动文件介绍
config.ru
config.ru
文件是 Rack 服务器的配置文件,用于启动 Rails 应用程序。内容如下:
# This file is used by Rack-based servers to start the application.
require_relative "config/environment"
run Rails.application
Rakefile
Rakefile
文件用于定义 Rake 任务,方便执行各种自动化任务。内容如下:
require_relative "config/application"
Rails.application.load_tasks
3. 项目的配置文件介绍
config/application.rb
config/application.rb
文件是应用程序的主要配置文件,包含应用程序的基本设置和加载路径。内容如下:
require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module DddRailsSample
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after these configurations.
end
end
config/database.yml
config/database.yml
文件用于配置数据库连接信息。内容如下:
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
config/environments/development.rb
config/environments/development.rb
文件用于配置开发环境。内容如下:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
#