Ruby on Rails Directory Structure Like Below:
demo/ ..../app ......../controller ......../helpers ......../models ......../views ............../layouts ..../components ..../config ..../db ..../doc ..../lib ..../log ..../public ..../script ..../test ..../tmp ..../vendor README Rakefile
Directory or File Meaning:
app : This organizes your application components. It's got subdirectories that hold the view (views and helpers), controller (controllers), and the backend business logic (models).
app/controllers: The controllers subdirectory is where Rails looks to find controller classes. A controller handles a web request from the user.
app/helpers: The helpers subdirectory holds any helper classes used to assist the model, view, and controller classes. This helps to keep the model, view, and controller code small, focused, and uncluttered.
app/models: The models subdirectory holds the classes that model and wrap the data stored in our application's database. In most frameworks, this part of the application can grow pretty messy, tedious, verbose, and error-prone. Rails makes it dead simple!
app/view: The views subdirectory holds the display templates to fill in with data from our application, convert to HTML, and return to the user's browser.
app/view/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.
components : This directory holds components tiny self-contained applications that bundle model, view, and controller.
config: This directory contains the small amount of configuration code that your application will need, including your database configuration (in database.yml), your Rails environment structure (environment.rb), and routing of incoming web requests (routes.rb). You can also tailor the behavior of the three Rails environments for test, development, and deployment with files found in the environments directory.
db: Usually, your Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.
doc: Ruby has a framework, called RubyDoc, that can automatically generate documentation for code you create. You can assist RubyDoc with comments in your code. This directory holds all theR ubyDoc-generated Rails and application documentation.
lib: You'll put libraries here, unless they explicitly belong elsewhere (such as vendor libraries).
log: Error logs go here. Rails creates scripts that help you manage various error logs. You'll find separate logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).
public: Like the public directory for a web server, this directory has web files that don't change, such a s JavaScript files (public/javascripts), graphics (public/images), stylesheets (public/stylesheets), and HTML files (public).
script: This directory holds scripts to launch and manage the various tools that you'll use with Rails. For example, there are scripts to generate code (generate) and launch the web server (server).
test: The tests you write and those Rails creates for you all go here. You'll see a subdirectory for mocks (mocks), unit tests (unit), fixtures (fixtures), and functional tests (functional).
tmp: Rails uses this directory to hold temporary files for intermediate processing.
vendor: Libraries provided by third-party vendors (such as security libraries or database utilities beyond the basic Rails distribution) go here.
Apart from these directories there will be two files available in demo directory.
README: This file contains a basic detail about Rail Application and description of the directory structure explained above.
Rakefile: This file is similar to Unix Makefile which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation.
----------------------------------------------------------------------------------------------------------------------------------------
檔案/目錄 | 用途 |
---|---|
Gemfile | 設定Rails應用程式會使用哪些Gems套件 |
README | 專案說明:你可以用來告訴其他人你的應用程式是做什麼用的,如何使用等等。 |
Rakefile | 用來載入可以被命令列執行的一些Rake任務 |
app/ | 放Controllers、Models和Views檔案,接下來的內容主要都在這個目錄。 |
config/ | 應用程式設定檔、路由規則、資料庫設定等等 |
config.ru | 用來啟動應用程式的Rack伺服器設定檔 |
db/ | 資料庫的結構綱要 |
doc/ | 用來放你的文件 |
lib/ | 放一些自定的Module和類別檔案 |
log/ | 應用程式的Log記錄檔 |
public/ | 唯一可以在網路上看到的目錄,這是你的圖檔、JavaScript、CSS和其他靜態檔案擺放的地方 |
script/ | 放rails這個指令和放其他的script指令 |
test/ | 單元測試、fixtures及整合測試等程式 |
tmp/ | 暫時性的檔案 |
vendor/ | 用來放第三方程式碼外掛的目錄 |
----------------------------------------------------------------------------------------------------------------------------------------
下面是一个Rails项目通常的目录结构
├─app
│ ├─controllers
│ ├─helpers
│ ├─models
│ └─views
│ ├─admin
│ ├─layouts
│ ├─login
│ ├─search
│ └─store
├─components
├─config
│ └─environments
├─coverage
├─db
│ └─migrate
├─doc
│ └─app
│ ├─classes
│ └─files
│ ├─app
│ │ ├─controllers
│ │ ├─helpers
│ │ └─models
│ └─doc
├─lib
│ └─tasks
├─log
├─nbproject
│ └─private
├─public
│ ├─images
│ ├─javascripts
│ └─stylesheets
├─script
│ ├─performance
│ └─process
├─test
│ ├─fixtures
│ │ └─performance
│ ├─functional
│ ├─integration
│ ├─mocks
│ │ ├─development
│ │ └─test
│ ├─performance
│ └─unit
│ └─performance
├─tmp
│ ├─cache
│ ├─pids
│ ├─sessions
│ └─sockets
└─vendor
└─plugins
下面来解释这些目录的含义
app:Model,View,Controller都在这个目录下,对应的有子目录,我们大部分的工作都在这里进行。
Components:可复用的组件都放在这里。
Config:数据库链接等的配置信息。
Coverage:这个不是Rails自己的目录,是我们在前面测试时安装的测试覆盖率工具的目录。
Db:存放DB结构(Schema)的信息。
Doc:存放文档,我们前面生成过一次depot项目的文档,都在这里面。
Lib:存放共享的代码。
Log:我们的项目的日志信息,里面有development.log,production.log,server.log,test.log,我们在开发时的信息都写在development.log里,而测试时的log都写在test.log里。
Nbproject:这个不是Rails的目录,是我们前面用NetBeans创建depot项目的时候生成的。
Public:可以从Web访问的目录,如果我们在浏览器的地址栏里直接输入:http://localhost:3003/那么看到的就是这里的index.html页面。另外,我们前面也把一些css文件放在了这里的stylesheet目录里。
Script:Rails用到的脚本,有一些我们可能已经用过了,比如:generate,process,performance。
Test:Model测试,功能测试,测试用的数据等等,我们前面在这个目录下已经写了很多代码了。
Server:运行WEBrick服务器,我们前面在depot项目里已经使用了。
Vendor:存放第三方的代码。
下面再主要说说Script目录下的脚本,主要的脚本有:
l Benchmarker:对比多个方法的性能。
l Breakpointer:断点,能够让你和Rails应用程序交互。
l Console:让你能够使用irb命令和rails应用程序交互。
l Destroy:移除generate生成的文件。
l Generate:代码生成器,能够生成Controller,Mailer,Model,Web服务等。你还可以从Rails的网站上下载一些扩展的生成器模块。
l Profiler:对你的程序进行性能测试,使用方面前面的随笔也已经介绍过了。
Runner:可以使我们代码中的方法脱离Web的上下文环境来运行。--------------------------
Rails版本:3.2.13下,文件的目录好像有了变化。
比如图片文件要放到\public\images\下,css要直接放到\public下,具体的位置可以从服务端日志中看到
Reference:http://www.tutorialspoint.com/ruby-on-rails/rails-directory-structure.htm
http://ihower.tw/rails3/firststep.html
http://www.cnblogs.com/dahuzizyd/archive/2007/12/14/ruby_rails_dotnet_study_31.html