开源项目 m 的使用教程
mA Test::Unit runner that can run tests by line number.项目地址:https://gitcode.com/gh_mirrors/m/m
1. 项目的目录结构及介绍
m/
├── README.md
├── app
│ ├── controllers
│ │ └── application_controller.rb
│ ├── models
│ └── views
│ ├── layouts
│ │ └── application.html.erb
│ └── pages
│ └── home.html.erb
├── config
│ ├── application.rb
│ ├── database.yml
│ ├── routes.rb
│ └── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── db
│ └── migrate
├── public
│ └── index.html
├── Gemfile
└── Gemfile.lock
目录结构介绍
- README.md: 项目说明文件。
- app: 包含应用程序的主要代码。
- controllers: 控制器文件,处理用户请求。
- models: 模型文件,处理数据逻辑。
- views: 视图文件,负责展示数据。
- layouts: 布局文件,定义页面结构。
- pages: 具体页面视图文件。
- config: 配置文件目录。
- application.rb: 应用程序配置文件。
- database.yml: 数据库配置文件。
- routes.rb: 路由配置文件。
- environments: 不同环境下的配置文件。
- db: 数据库相关文件。
- migrate: 数据库迁移文件。
- public: 公共资源文件。
- Gemfile: 依赖管理文件。
- Gemfile.lock: 依赖锁定文件。
2. 项目的启动文件介绍
项目的启动文件主要是 config/application.rb
和 config/routes.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 M
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
end
end
config/routes.rb
该文件定义了应用程序的路由规则,决定了 URL 如何映射到控制器和动作。
Rails.application.routes.draw do
root 'pages#home'
get 'pages/home'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
3. 项目的配置文件介绍
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
该文件包含了开发环境的特定配置,如日志级别、缓存设置等。
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
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load
mA Test::Unit runner that can run tests by line number.项目地址:https://gitcode.com/gh_mirrors/m/m