Rails的文件结构(Directory structure of a Rails application)

本文介绍了使用NetBeans创建Ruby on Rails项目时的目录结构。详细解释了各目录的作用,如app目录下控制器、模型和视图文件的位置,以及配置、测试等文件夹的内容。
When you ask NetBeans to create a Rails project  - internally NetBeans uses the rails' helper script -, it creates the entire directory structure for your application. Rails knows where to find things it needs within this structure, so you don't have to tell it explicitly.

The directory structure of a Rails application looks as following.  Please note that NetBeans uses logical names to reflect these directories. For example, the Controllers node represents app/controllers directory while Models node represents app/models.  If you click Files view of the project, you will see the directories mentioned below.

app
Holds all the code that's specific to this particular application.
app/controllers
Holds controllers that should be named like hello_controller.rb for automated URL mapping. 
All controllers should descend from ApplicationController which itself descends from ActionController::Base.
app/models
Holds models that should be named like message.rb.
Most models will descend from ActiveRecord::Base.
app/views
Holds the template files for the view that should be named like hello/say_hello.rhtml for the HelloController#say_hello action. 
app/views/layouts
Holds the template files for layouts to be used with views. 
This models the common header/footer method of wrapping views. In your views, define a layout using the <tt>layout :default</tt> and create a file named default.rhtml. Inside default.rhtml, call <% yield %> to render the view using this layout.
app/helpers
Holds view helpers that should be named like hello_helper.rb. These are generated for you automatically when using script/generate for controllers. Helpers can be used to wrap functionality for your views into methods.
config
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
components
Self-contained mini-applications that can bundle together controllers, models, and views.
db
Contains the database schema in schema.rb.  
db/migrate
Contains all the sequence of Migrations for your schema.
doc
This directory is where your application documentation will be stored when generated using <tt>rake doc:app</tt>
lib
Application specific libraries. Basically, any kind of custom code that doesn't belong under controllers, models, or helpers. This directory is in the load path.
public 
The directory available for the web server. 
Contains subdirectories for images, stylesheets, and javascripts. 
Also contains the dispatchers and the default HTML files. 
This should be set as the DOCUMENT_ROOT of your web server.
script
Helper scripts for automation and generation.
test
Unit and functional tests along with fixtures. When using the script/generate scripts, template test files will be generated for you and placed in this directory.
vendor 
External libraries that the application depends on. Also includes the plugins subdirectory.
This directory is in the load path.
Physical directories that are created for the Ruby on Rails project

Usage: rails new APP_PATH [options] Options: [--skip-namespace] # Skip namespace (affects only isolated engines) # Default: false [--skip-collision-check] # Skip collision check # Default: false -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: C:/Ruby34-x64/bin/ruby.exe -n, [--name=NAME] # Name of the app -m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) -d, [--database=DATABASE] # Preconfigure for selected database # Default: sqlite3 # Possible values: mysql, trilogy, postgresql, sqlite3, mariadb-mysql, mariadb-trilogy -G, [--skip-git] # Skip git init, .gitignore and .gitattributes [--skip-docker] # Skip Dockerfile, .dockerignore and bin/docker-entrypoint [--skip-keeps] # Skip source control .keep files -M, [--skip-action-mailer] # Skip Action Mailer files [--skip-action-mailbox] # Skip Action Mailbox gem [--skip-action-text] # Skip Action Text gem -O, [--skip-active-record] # Skip Active Record files [--skip-active-job] # Skip Active Job [--skip-active-storage] # Skip Active Storage files -C, [--skip-action-cable] # Skip Action Cable files -A, [--skip-asset-pipeline] # Skip the asset pipeline setup -J, --skip-js, [--skip-javascript] # Skip JavaScript files [--skip-hotwire] # Skip Hotwire integration [--skip-jbuilder] # Skip jbuilder gem -T, [--skip-test] # Skip test files [--skip-system-test] # Skip system test files [--skip-bootsnap] # Skip bootsnap gem [--skip-dev-gems] # Skip development gems (e.g., web-console) [--skip-thruster] # Skip Thruster setup [--skip-rubocop] # Skip RuboCop setup [--skip-brakeman] # Skip brakeman setup [--skip-bundler-audit] # Skip bundler-audit setup [--skip-ci] # Skip GitHub CI files [--skip-kamal] # Skip Kamal setup [--skip-solid] # Skip Solid Cache, Queue, and Cable setup [--dev], [--no-dev], [--skip-dev] # Set up the application with Gemfile pointing to your Rails checkout [--devcontainer], [--no-devcontainer], [--skip-devcontainer] # Generate devcontainer files [--edge], [--no-edge], [--skip-edge] # Set up the application with a Gemfile pointing to the 8-1-stable branch on the Rails repository --master, [--main], [--no-main], [--skip-main] # Set up the application with Gemfile pointing to Rails repository main branch [--rc=RC] # Path to file containing extra configuration options for rails command [--no-rc] # Skip loading of extra configuration options from .railsrc file [--api], [--no-api], [--skip-api] # Preconfigure smaller stack for API only apps # Default: false [--minimal], [--no-minimal], [--skip-minimal] # Preconfigure a minimal rails app -j, --js, [--javascript=JAVASCRIPT] # Choose JavaScript approach # Default: importmap # Possible values: importmap, bun, webpack, esbuild, rollup -c, [--css=CSS] # Choose CSS processor. Check https://github.com/rails/cssbundling-rails for more options # Possible values: tailwind, bootstrap, bulma, postcss, sass -B, [--skip-bundle] # Don't run bundle install [--skip-decrypted-diffs] # Don't configure git to show decrypted diffs of encrypted credentials Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend], [--skip-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet], [--skip-quiet] # Suppress status output -s, [--skip], [--no-skip], [--skip-skip] # Skip files that already exist Rails options: -h, [--help], [--no-help], [--skip-help] # Show this help message and quit -v, [--version], [--no-version], [--skip-version] # Show Rails version number and quit Description: The `rails new` command creates a new Rails application with a default directory structure and configuration at the path you specify. You can specify extra command-line arguments to be used every time `rails new` runs in the .railsrc configuration file in your home directory, or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set. Note that the arguments specified in the .railsrc file don't affect the default values shown above in this help message. You can specify which version to use when creating a new rails application using `rails _<version>_ new`. Examples: `rails new ~/Code/Ruby/weblog` This generates a new Rails app in ~/Code/Ruby/weblog. `rails _<version>_ new weblog` This generates a new Rails app with the provided version in ./weblog. `rails new weblog --api` This generates a new Rails app in API mode in ./weblog. `rails new weblog --skip-action-mailer` This generates a new Rails app without Action Mailer in ./weblog. Any part of Rails can be skipped during app generation.
11-13
PS E:\rubyProject\student_curd> bundle exec rails server Usage: rails new APP_PATH [options] Options: [--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated engines) [--skip-collision-check], [--no-skip-collision-check] # Skip collision check -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: E:/Bitnami/redmine-5.0.3-0/ruby/bin/ruby.exe -m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/postgresql/sqlite3/oracle/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) # Default: sqlite3 [--skip-gemfile], [--no-skip-gemfile] # Don't create a Gemfile -G, [--skip-git], [--no-skip-git] # Skip .gitignore file [--skip-keeps], [--no-skip-keeps] # Skip source control .keep files -M, [--skip-action-mailer], [--no-skip-action-mailer] # Skip Action Mailer files [--skip-action-mailbox], [--no-skip-action-mailbox] # Skip Action Mailbox gem [--skip-action-text], [--no-skip-action-text] # Skip Action Text gem -O, [--skip-active-record], [--no-skip-active-record] # Skip Active Record files [--skip-active-job], [--no-skip-active-job] # Skip Active Job [--skip-active-storage], [--no-skip-active-storage] # Skip Active Storage files -P, [--skip-puma], [--no-skip-puma] # Skip Puma related files -C, [--skip-action-cable], [--no-skip-action-cable] # Skip Action Cable files -S, [--skip-sprockets], [--no-skip-sprockets] # Skip Sprockets files [--skip-spring], [--no-skip-spring] # Don't install Spring application preloader [--skip-listen], [--no-skip-listen] # Don't generate configuration that depends on the listen gem -J, [--skip-javascript], [--no-skip-javascript] # Skip JavaScript files [--skip-turbolinks], [--no-skip-turbolinks] # Skip turbolinks gem [--skip-jbuilder], [--no-skip-jbuilder] # Skip jbuilder gem -T, [--skip-test], [--no-skip-test] # Skip test files [--skip-system-test], [--no-skip-system-test] # Skip system test files [--skip-bootsnap], [--no-skip-bootsnap] # Skip bootsnap gem [--dev], [--no-dev] # Set up the application with Gemfile pointing to your Rails checkout [--edge], [--no-edge] # Set up the application with Gemfile pointing to Rails repository [--master], [--no-master] # Set up the application with Gemfile pointing to Rails repository main branch [--rc=RC] # Path to file containing extra configuration options for rails command [--no-rc], [--no-no-rc] # Skip loading of extra configuration options from .railsrc file [--api], [--no-api] # Preconfigure smaller stack for API only apps [--minimal], [--no-minimal] # Preconfigure a minimal rails app -B, [--skip-bundle], [--no-skip-bundle] # Don't run bundle install --webpacker, [--webpack=WEBPACK] # Preconfigure Webpack with a particular framework (options: react, vue, angular, elm, stimulus) [--skip-webpack-install], [--no-skip-webpack-install] # Don't run Webpack install Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist Rails options: -h, [--help], [--no-help] # Show this help message and quit -v, [--version], [--no-version] # Show Rails version number and quit Description: The 'rails new' command creates a new Rails application with a default directory structure and configuration at the path you specify. You can specify extra command-line arguments to be used every time 'rails new' runs in the .railsrc configuration file in your home directory, or in $XDG_CONFIG_HOME/rails/railsrc if XDG_CONFIG_HOME is set. Note that the arguments specified in the .railsrc file don't affect the defaults values shown above in this help message. Example: rails new ~/Code/Ruby/weblog This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
09-09
成都市作为中国西部地区具有战略地位的核心都市,其人口的空间分布状况对于城市规划、社会经济发展及公共资源配置等研究具有基础性数据价值。本文聚焦于2019年度成都市人口分布的空间数据集,该数据以矢量格式存储,属于地理信息系统中常用的数据交换形式。以下将对数据集内容及其相关技术要点进行系统阐述。 Shapefile 是一种由 Esri 公司提出的开放型地理空间数据格式,用于记录点、线、面等几何要素。该格式通常由一组相互关联的文件构成,主要包括存储几何信息的 SHP 文件、记录属性信息的 DBF 文件、定义坐标系统的 PRJ 文件以及提供快速检索功能的 SHX 文件。 1. **DBF 文件**:该文件以 dBase 表格形式保存与各地理要素相关联的属性信息,例如各区域的人口统计数值、行政区划名称及编码等。这类表格结构便于在各类 GIS 平台中进行查询与编辑。 2. **PRJ 文件**:此文件明确了数据所采用的空间参考系统。本数据集基于 WGS84 地理坐标系,该坐标系在全球范围内广泛应用于定位与空间分析,有助于实现跨区域数据的准确整合。 3. **SHP 文件**:该文件存储成都市各区(县)的几何边界,以多边形要素表示。每个多边形均配有唯一标识符,可与属性表中的相应记录关联,实现空间数据与统计数据的联结。 4. **SHX 文件**:作为形状索引文件,它提升了在大型数据集中定位特定几何对象的效率,支持快速读取与显示。 基于上述数据,可开展以下几类空间分析: - **人口密度评估**:结合各区域面积与对应人口数,计算并比较人口密度,识别高密度与低密度区域。 - **空间集聚识别**:运用热点分析(如 Getis-Ord Gi* 统计)或聚类算法(如 DBSCAN),探测人口在空间上的聚集特征。 - **空间相关性检验**:通过莫兰指数等空间自相关方法,分析人口分布是否呈现显著的空间关联模式。 - **多要素叠加分析**:将人口分布数据与地形、交通网络、环境指标等其他地理图层进行叠加,探究自然与人文因素对人口布局的影响机制。 2019 年成都市人口空间数据集为深入解析城市人口格局、优化国土空间规划及完善公共服务体系提供了重要的数据基础。借助地理信息系统工具,可开展多尺度、多维度的定量分析,从而为城市管理与学术研究提供科学依据。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值