Ruby on Rails 中的“脚手架”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5776007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:59:26  来源:igfitidea点击:

What does “scaffold” mean in Ruby on Rails?

ruby-on-rails

提问by user658213

I am studying a guide in which scaffold is mentioned. I don't understand what it is.

我正在研究一个指南,其中提到了脚手架。我不明白它是什么。

Is it sort of built-in framework?

它是一种内置框架吗?

回答by denisjacquemin

see rails guidefor the explanation

有关解释,请参阅rails 指南

Rails scaffolding is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.

Rails 脚手架是一种快速生成应用程序一些主要部分的方法。如果您想在单个操作中为新资源创建模型、视图和控制器,脚手架是该工作的工具。

回答by Phillip Whelan

Scaffolding in Ruby on Rails refers to the auto generation of a simple set of a model, views and controller usually for a single table.

Ruby on Rails 中的脚手架是指通常为单个表自动生成一组简单的模型、视图和控制器。

For example:

例如:

user@localhost$ ./scripts/generate scaffold users

Would create a full CRUD (create, read, update, delete) web interface for the Users table. Of course features like hashing the password, uploading images, etc... are not handled and must be added to the auto-generated code.

将为用户表创建一个完整的 CRUD(创建、读取、更新、删除)Web 界面。当然,散列密码、上传图像等功能不会被处理,必须添加到自动生成的代码中。

回答by Mishlaev Vitaliy

I'm also studying Ruby On Rails from the scratch. Here is how I remember it: Each scaffold is an object inside your application, that users will interact with. User can create this object, or update, or read, or delete. At facebook one of this objects is status. Each user can create it, read, delete or update status. At twitter it's tweet. At pinterest it's pins.

我也在从头开始学习 Ruby On Rails。这是我的记忆:每个脚手架都是应用程序中的一个对象,用户将与之交互。用户可以创建这个对象,或者更新,或者读取,或者删除。在 facebook,这个对象之一是status。每个用户都可以创建、读取、删除或更新状态。在 twitter 它是tweet。在 pinterest 上是pin

Every applications contains a lot of such objects — statuses, photos, comments, users, etc. You just have to plan all of then and design future interactions between this objects and users of your application.

每个应用程序都包含很多这样的对象——状态、照片、评论、用户等。你只需要计划所有这些,并设计这些对象和应用程序用户之间的未来交互。

回答by Brian Joseph Spinos

In rails 3.2 when you type this in the TERMINAL, inside your rails app folder:

在 rails 3.2 中,当您在 Rails 应用程序文件夹内的 TERMINAL 中键入以下内容时:

rails generate scaffold User
  • the "User" part could be any name you choose...

  • it creates all of the the structure for your CRUD (create, read, update, delete)

  • in this creation it includes the controller, model, and views the views for each part of the CRUD (create, read, update, delete),

  • and the code inside them to start you off with your CRUD (create, read, update, delete)

  • its way easier to do this, instead of coding everything yourself, it saves you lots of time!

  • “用户”部分可以是您选择的任何名称...

  • 它为您的 CRUD 创建所有结构(创建、读取、更新、删除)

  • 在此创建中,它包括控制器、模型和视图,CRUD 的每个部分(创建、读取、更新、删除)的视图,

  • 以及其中的代码,让您开始使用 CRUD(创建、读取、更新、删除)

  • 它的方式更容易做到这一点,而不是自己编码一切,它为您节省了大量时间!

回答by Al Ameen

lets have a simple example

让我们举一个简单的例子

we want to have an app with two data model one is user model with user_id,name and email and another is the post model with id and content.

我们想要一个具有两个数据模型的应用程序,一个是带有 user_id、name 和 email 的用户模型,另一个是带有 id 和内容的 post 模型。

we want to associate each post model with a particular user. we will accomplish this by recording the user_id of the owner of the post.

我们希望将每个帖子模型与特定用户相关联。我们将通过记录帖子所有者的 user_id 来完成此操作。

by using rails scaffolding command you can create rails scaffold command rails will generate the models and controller for the two data model.

通过使用 rails scaffolding 命令,您可以创建 rails scaffold 命令 rails 将为两个数据模型生成模型和控制器。

you can save a lot of time

你可以节省很多时间