如何反转“rails 生成”

发布于 2024-10-02 09:36:23 字数 108 浏览 9 评论 0 原文

我想删除它创建的所有文件并回滚所做的任何更改,但不一定是数据库,而是回滚配置文件。

我想自动删除在routes.rb 文件中删除的模型/控制器的所有资源映射以及可能已进行更改的其他位置?

I want to delete all the files it created and roll back any changes made, but not necessarily to the database, but more to the config files.

I'd like to automatically delete all the resource mappings for the model/controller deleted in the routes.rb file and everywhere else that changes might have been made?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

樱桃奶球 2024-10-09 09:36:24

这是在 Rails 中生成或销毁控制器或模型的原型:

rails generate/destroy controller/model [controller/model Name]

例如,如果您需要生成用户控制器:

rails generate controller User

或者

rails g controller User

如果您想销毁用户控制器或恢复到上述操作
然后使用:

rails destroy controller User

或:

rails d controller User

在此处输入图像描述

This is a prototype to generate or destroy a controller or model in Rails:

rails generate/destroy controller/model [controller/model Name]

For example, if you need to generate a User Controller:

rails generate controller User

or

rails g controller User

If you want to destroy the User controller or revert to above action
then use:

rails destroy controller User

or:

rails d controller User

enter image description here

绝對不後悔。 2024-10-09 09:36:24

您可以使用rails d model/controller/migration ...来销毁或删除使用railsgenerate命令生成的更改。

例如:

rails g model Home name:string

创建一个名为 home 且属性为 name 的模型。要删除该命令生成的文件和代码,我们可以使用

rails d model Home

You could use rails d model/controller/migration ... to destroy or remove the changes generated by using the rails generate command.

For example:

rails g model Home name:string

creates a model named home with attribute name. To remove the files and code generated from that command we can use

rails d model Home
兲鉂ぱ嘚淚 2024-10-09 09:36:24

如果您使用 Rails,请使用 rails dcontroller Users

并且,如果您使用 Zeus,请使用 zeus d 控制器用户

另一方面,如果您使用 git 或 SVN,请使用提交号恢复更改。这要快得多。

If you use Rails, use rails d controller Users.

And, if you use Zeus, use zeus d controller Users.

On the other hand, if you are using git or SVN, revert your changes with the commit number. This is much faster.

噩梦成真你也成魔 2024-10-09 09:36:24

在恢复rails生成之前,请确保先回滚迁移

情况 1:如果您想恢复脚手架,则运行此命令:

rails destroy scaffold MODEL_NAME

情况 2:如果您想恢复模型,则运行此命令:

rails destroy model MODEL_NAME

情况 3:如果您想恢复控制器,则运行此命令:

rails destroy controller CONTROLLER_NAME

注意:您还可以使用快捷方式 < code>d 而不是 destroy

Before reverting the rails generate, please make sure you rollback the migration first.

Case 1: if you want to revert scaffold then run this command:

rails destroy scaffold MODEL_NAME

Case 2: if you want to revert model then run this command:

rails destroy model MODEL_NAME

Case 3: if you want to revert controller then run this command:

rails destroy controller CONTROLLER_NAME

Note: you can also use shortcut d instead of destroy.

冷情妓 2024-10-09 09:36:24

你可以摧毁所有以同样方式创造的东西,除了一点点改变。
对于控制器,

rails d controller_name (d stands for destroy)

对于模型,

rails d model_name

您只需在迁移中放置 d(destroy) 而不是 g(generate)

You can destroy all things that was created same way except little thing change.
For controller,

rails d controller_name (d stands for destroy)

For Model

rails d model_name

you just put d(destroy) instead of g(generate) in your migration.

善良天后 2024-10-09 09:36:24

如果您希望手动删除控制器:

对于控制器welcome

rm app/controllers/welcome_controller.rb
rm app/views/welcome
rm test/controllers/welcome_controller_test.rb
rm app/helpers/welcome_helper.rb
rm test/helpers/welcome_helper_test.rb
rm app/assets/javascripts/welcome.js.coffee
rm app/assets/stylesheets/welcome.css.scss

If you prefer to delete the controller manually:

For controller welcome

rm app/controllers/welcome_controller.rb
rm app/views/welcome
rm test/controllers/welcome_controller_test.rb
rm app/helpers/welcome_helper.rb
rm test/helpers/welcome_helper_test.rb
rm app/assets/javascripts/welcome.js.coffee
rm app/assets/stylesheets/welcome.css.scss
吹梦到西洲 2024-10-09 09:36:24

您可以

rails g/generate controller/model/migration xxx

使用以下方法恢复输出:

 rails d/destroy controller/model/migration xxx

You can revert your

rails g/generate controller/model/migration xxx

output by using:

 rails d/destroy controller/model/migration xxx
假扮的天使 2024-10-09 09:36:24

假设我创建了一个名为“sample”的控制器,如下所示:

rails generate controller sample

如果我必须销毁此控制器,我所要做的就是将 generatedestroy 交换,如

rails destroy controller sample.

如果你想要要反转生成,您只需将 generatedestroy 交换即可。

Suppose I have created a controller named "sample" like:

rails generate controller sample

If I have to destroy this controller, all I have to do is swap generate with destroy, as in

rails destroy controller sample.

If you want to reverse the generation, all you have to do is swap generate with destroy.

时光礼记 2024-10-09 09:36:24

您可以通过以下方式撤消 railsgenerate

  • 对于模型:rails destroy MODEL
  • 对于控制器:rails destroy controller_name

You can undo a rails generate in the following ways:

  • For the model: rails destroy MODEL
  • For the controller: rails destroy controller_name
昨迟人 2024-10-09 09:36:24

要反转 rails generated,请使用 rails destroy

rails destroy Model

请参阅“rails destroy”了解更多信息。

To reverse rails generate, use rails destroy:

rails destroy Model

See "rails destroy" for more information.

晨与橙与城 2024-10-09 09:36:24

所有版本的 Rails 都有一个“销毁”,因此,如果您使用生成器创建一个名为“任务”的(例如)脚手架,要销毁该生成步骤的所有更改,您将必须输入:

rails destroy scaffold Tasks

希望它对您有帮助。

All versions of rails have a "destroy", so-, if you create a (for example) scaffold named "tasks" using a generator, to destroy all the changes of that generate step you will have to type:

rails destroy scaffold Tasks

Hope it helps you.

说好的呢 2024-10-09 09:36:24

为了扭转这种情况,我们只需摧毁它。打开终端应用程序并转到项目目录,然后键入:

rails destroy model CamelCase
rails destroy controller CamelCase

其中 CamelCase 是任何模型或控制器的名称。
它将删除模型、迁移和一些相关的测试文件。 (运行命令后,您可以在终端窗口中看到结果。)

To reverse that, we just destroy it. Open the Terminal application and go to the project directory, then, type this:

rails destroy model CamelCase
rails destroy controller CamelCase

Where CamelCase is a name of any model or controller.
It will remove the model, migration and some of the related test files. (You can see the result in the Terminal window after you have run the command.)

静水深流 2024-10-09 09:36:24

我们使用生成为
rails 生成应用程序
因此,可以使用 destroy 语句来反转重新生成任何 generate 语句。
只需将 generate 替换为 destroy
railsgenerateapp可以写成railsdestroyapp'
rails 生成 ____asrails 销毁 ____`

We use generate as
rails generate app.
So regenerating any generate statement can be reversed using destroy statement.
Just replace generate with destroy
i.e. rails generate app can be written as rails destroy app'
rails generate ____asrails destroy ____`

满地尘埃落定 2024-10-09 09:36:24

删除了选定型号的脚手架:

bin/rails d scaffold <AccessControl> //model name

Removed scaffolding for selected model:

bin/rails d scaffold <AccessControl> //model name
梦明 2024-10-09 09:36:23
rails destroy controller lalala
rails destroy model yadayada
rails destroy scaffold hohoho

Rails 3.2 为该命令添加了一个新的 d 快捷方式,因此现在您可以编写:

rails d controller lalala
rails d model yadayada
rails d scaffold hohoho
rails destroy controller lalala
rails destroy model yadayada
rails destroy scaffold hohoho

Rails 3.2 adds a new d shortcut to the command, so now you can write:

rails d controller lalala
rails d model yadayada
rails d scaffold hohoho
束缚m 2024-10-09 09:36:23

值得一提的是这里的 -p 标志(“p”代表假装)。

如果您将其添加到命令中,它只会执行“测试”运行并显示将删除哪些文件,而不会实际删除它们。

$ rails d controller welcome -p

  remove  app/controllers/welcome_controller.rb
  invoke  erb
  remove    app/views/welcome
  invoke  test_unit
  remove    test/controllers/welcome_controller_test.rb
  invoke  helper
  remove    app/helpers/welcome_helper.rb
  invoke    test_unit
  remove      test/helpers/welcome_helper_test.rb
  invoke  assets
  invoke    coffee
  remove      app/assets/javascripts/welcome.js.coffee
  invoke    scss
  remove      app/assets/stylesheets/welcome.css.scss

如果您对此感到满意,请在不带 -p 标志的情况下再次运行该命令。

It's worth mentioning the -p flag here ("p" for pretend).

If you add this to the command it will simply do a "test" run and show you what files will be deleted without actually deleting them.

$ rails d controller welcome -p

  remove  app/controllers/welcome_controller.rb
  invoke  erb
  remove    app/views/welcome
  invoke  test_unit
  remove    test/controllers/welcome_controller_test.rb
  invoke  helper
  remove    app/helpers/welcome_helper.rb
  invoke    test_unit
  remove      test/helpers/welcome_helper_test.rb
  invoke  assets
  invoke    coffee
  remove      app/assets/javascripts/welcome.js.coffee
  invoke    scss
  remove      app/assets/stylesheets/welcome.css.scss

If you're happy with it, run the command again without the -p flag.

怕倦 2024-10-09 09:36:23

rails destroy controller Controller_name 返回了一堆错误。为了能够销毁控制器,我必须删除 paths.rb 中的相关路由。 PS我使用的是rails 3.1

rails destroy controller Controller_name was returning a bunch of errors. To be able to destroy controller I had to remove related routes in routes.rb. P.S. I'm using rails 3.1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文