Ror generate scaffold 到底做了些什么?

当我们通过命令创建一个 scaffold 时 rails到底为我们做了些什么呢?
rails generate scaffold Post name:string title:string content:text


官方文档是这样说的:

The scaffold generator will build several files in your application, along with some folders, and editconfig/routes.rb. Here’s a quick overview of what it creates:

File Purpose
db/migrate/20100207214725_create_posts.rb Migration to create the posts table in your database (your name will include a different timestamp)
app/models/post.rb The Post model
test/unit/post_test.rb Unit testing harness for the posts model
test/fixtures/posts.yml Sample posts for use in testing
config/routes.rb Edited to include routing information for posts
app/controllers/posts_controller.rb The Posts controller
app/views/posts/index.html.erb A view to display an index of all posts
app/views/posts/edit.html.erb A view to edit an existing post
app/views/posts/show.html.erb A view to display a single post
app/views/posts/new.html.erb A view to create a new post
app/views/posts/_form.html.erb A partial to control the overall look and feel of the form used in edit and new views
test/functional/posts_controller_test.rb Functional testing harness for the posts controller
app/helpers/posts_helper.rb Helper functions to be used from the post views
test/unit/helpers/posts_helper_test.rb Unit testing harness for the posts helper
app/assets/javascripts/posts.js.coffee CoffeeScript for the posts controller
app/assets/stylesheets/posts.css.scss Cascading style sheet for the posts controller
app/assets/stylesheets/scaffolds.css.scss Cascading style sheet to make the scaffolded views look better
脚手架会创建生成一些文件夹及文件,并修改 config/routes.rb 文件,下面是它生成文件的概述:

db/migrate/20100207214725_create_posts.rb         

                            在你的数据库中创建 posts(帖子)表的迁移 (你的文件名中时间会和例子里不一样)

app/models/post.rb  

                            posts(帖子)的模型 model

test/unit/post_test.rb

                            posts model 的单元测试

test/fixtures/posts.yml

                            用于测试的样例数据

config/routes.rb

                            包括posts操作的路由信息

app/controllers/posts_controller.rb

                            posts的控制器 controller

app/views/posts/index.html.erb

                            用来显示所有posts的视图 view(相当与增删改查中的list页面)

app/views/posts/edit.html.erb

app/views/posts/show.html.erb

app/views/posts/new.html.erb

            编辑、查看、新建posts的视图

app/views/posts/_form.html.erb

                             A partial to control the overall look and feel of the form used in edit and new views

test/functional/posts_controller_test.rb

                             posts控制器的功能测试

app/helpers/posts_helper.rb

                             post视图的帮助方法

test/unit/helpers/posts_helper_test.rb

                              posts helper的单元测试

app/assets/javascripts/posts.js.coffee

                              CoffeeScript for the posts controller

app/assets/stylesheets/posts.css.scss

                              posts控制器的样式

app/assets/stylesheets/scaffolds.css.scss

                               使脚手架视图更好看的样式


                       










  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值