rails框架下的文件夹及其作用
关键字: ruby rails学习从07年3月份开始研究rails, 到了6月份终止,期间有很多收获,没有记录下来,现在有了些空余时间,开始继续学习,才发现,好记性不如乱笔头,后悔没将当初的所得记下来,现在发现来最最基本的都忘了差不多了。。
创建一个rails框架,以下包含这些文件,其作用如下:(参考《Rails Cookbook》第二章,2.1节)
app
Contains all the code that's specific to this particular application. Most of Rails development happens within the app directory.
包含所有这个应用的代码。大多数Rails的开发都在这个目录下。
app/controllers
Contains controller classes, all of which should inherit ActionController::Base. Each of these files should be named after the model they control followed by _controller.rb (e.g., cookbook_controller.rb) for automatic URL mapping to occur.
包含控制器的类,所有的应该继承自ActionController::Base。所有这些文件中的每一个应该命名为在他们的Model名后面加上_controller.rb(例如,cookbook_controller.rb),目的是URL能够自动匹配到他们。
app/models
Holds models that should be named like cookbook.rb. Most of the time model classes inherit from ActiveRecord::Base.
Models 应该被命名为象 Cookbook.rb, 大多数Model类继承自ActiveRecord::Base.
app/views
Holds the template files for the view that should be named, such as cookbook/index.rhtml for the CookBookController#index action. All views use eRuby syntax. This directory can also be used to keep stylesheets, images, and so on, that can be symlinked to public.
所有的能够看见的模板文件应该这样命名,例如,cookbook/index.rhtml 是CookBookController#index action所产生的,所有的Views文件使用eRuby语法。这个目录也能被使用保存样式表,图片等等,他们能够被动态的链接。
app/helpers
Holds view helpers that should be named, such as weblog_helper.rb.
帮助文件应该这样命名, 例如,weblog_helper.rb.
app/apis
保存API类为Web服务。
config
Contains configuration files for the Rails environment, the routing map, the database, and other dependencies.
包含配置文件为Rails的环境,路径映射,以及其他的依赖。
components
Holds 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.
包含数据库的计划在schema.rb。db/migrate 包含所有一系列的计划的migrations。
lib
Contains application-specific librariesbasically, 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 Java scripts. Also contains the dispatchers and the default HTML files.
这个目录使所有的Web服务可能。包含子目录为了保存图片,样式表,Java scripts脚本,也包含可调度的和默认的HTML文件。
script
保存helper脚本自动的和产生的。
vendor
-
Holds external libraries that the application depends on. Also includes the plug-ins subdirectory. This directory is in the load path.
-
包含应用程序依赖的第三方库,也包含子目录的插件。这个目录在导入路径中。
- 这个说的可能更加形象:
- 1:Controllers 目录存放 rails 应用中相应的 controller 类,controller 类处理来自用户 的 web 请求。
2:views 目录存放相应的模板文件,模板文件填充数据后,转换为 html 格式传递给用户的浏 览器。
3:models 目录存放数据模型类,模型类封装了数据库中的数据。很多框架在数据模型层都做 的比较复杂,用过 rails 后,你会发现它非常容易使用。
4:helpers 目录存放了简化 Controllers, models, views 使用的帮助类。







评论排行榜