简体   繁体   English

为什么Ruby on Rails弃用了scaffold方法

[英]Why did Ruby on Rails deprecate the scaffold method

I am learning Ruby on Rails so I'm sure I'll find this out sooner or later. 我正在学习Ruby on Rails,所以我相信我迟早会发现它。

Why would the scaffold method be deprecated in version 2 of Rails? 为什么在Rails的第2版中不推荐使用scaffold方法?

The scaffold method went against the spirit of scaffolding, which is meant to give you a starting point that you are supposed to build upon for your own needs. 脚手架方法违背了脚手架的精神,这意味着为您提供一个起点,您应该根据自己的需要进行构建。 By generating the scaffold dynamically, there is nothing for you to edit. 通过动态生成脚手架,您无需编辑任何内容。

The new way with the scaffold generator lets you edit the scaffolded files so you can use it to build what you actually need. 使用脚手架生成器的新方法允许您编辑脚手架文件,以便您可以使用它来构建您实际需要的内容。

I am assuming you are referring to Dynamic Scaffolding, as the scaffold generator is still around and going strong. 我假设你指的是动态脚手架,因为脚手架发电机仍然存在且变强。

David Heinemeier Hansson is on record as saying that Dynamic Scaffolding looked great in demos, but since the whole point of Dynamic Scaffolding was to teach people to use rails, abstracting it away in a single line of code was more a curse then a blessing, as no one uses Dynamic Scaffolding in production code . 大卫海涅迈尔汉森有记录说,动态脚手架在演示中看起来很棒,但是因为动态脚手架的重点是教人们使用轨道,所以用一行代码将它抽象出来更像是一种诅咒而不是祝福,就像没有人在生产代码中使用动态脚手架。 . . just for demos and tutorials. 仅用于演示和教程。

If you have a copy of AWDWR handy, you can read about his whole explanation on about p81 in the latest(3rd) edition (I didn't want to copy paste). 如果你有一份AWDWR的副本,你可以在最新的(第3版)中阅读关于p81的完整解释(我不想复制粘贴)。

You can still: script/generate scaffold model_name to generate your scaffolded model. 您仍然可以:脚本/生成脚手架model_name来生成您的脚手架模型。

There is however still a Rails plugin out there that will do just what the scaffold method did before. 然而,仍有一个Rails插件可以完成脚手架方法之前的操作。 It's called ActiveScaffold . 它叫做ActiveScaffold

Because people thought it was supposed to be used for production, which would be a horrible idea. 因为人们认为它应该被用于生产,这将是一个可怕的想法。 Instead you generate a scaffold which you can then easily edit and get it production ready from there. 而是生成一个脚手架,然后您可以轻松编辑并从那里准备好生产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM