Ruby-on-rails Rails“脚本/生成模型”的文档在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/514216/
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-02 20:57:05  来源:igfitidea点击:

Where are the docs for Rails "script/generate model"?

ruby-on-railsscriptgenerate

提问by Dan Rosenstark

I am running

我在跑步

ruby script/generate scaffold

or

或者

ruby script/generate model

and I know the basic syntax, like

我知道基本的语法,比如

ruby script/generate scaffold Dude name:string face:boolean

but I do not know things like:

但我不知道这样的事情:

  • should names of variables have underscores or be camelCased?
  • what kind of variable types are acceptable?
  • 变量的名称应该有下划线还是驼峰式?
  • 什么样的变量类型是可以接受的?

Where can I find such information?

我在哪里可以找到此类信息?

回答by Andrew Vit

Type the command without arguments and the documentation is revealed:

键入不带参数的命令并显示文档:

$ script/generate model

You can use either camelcase or underscores for the model name.

您可以使用驼峰式大小写或下划线作为模型名称。

  • Model names are singular; controller names are plural.
  • Field names use underscores.
  • 型号名称是单数;控制器名称是复数。
  • 字段名称使用下划线。

I can't remember all the possible field types, I just look them up from the Migration docs, as linked above.

我不记得所有可能的字段类型,我只是从上面链接的迁移文档中查找它们。

回答by Ronnie Liew

This document on Rails Migrationwould help.

这份关于Rails 迁移的文档会有所帮助。

With respect to the naming convention, I think the general adopted convention for Ruby on Rails is to have underscores.

关于命名约定,我认为 Ruby on Rails 普遍采用的约定是使用下划线。

To know which variable types are acceptable, refer to the section on Database Mapping.

要了解哪些变量类型是可接受的,请参阅有关数据库映射的部分。

回答by drew.macleod

There is a resource on the rails wiki as a List of Available Generators.

在 rails wiki 上有一个可用生成器列表的资源。

回答by Eric Davis

To check Rails naming conventions, topfunky's Pluralizerwas useful.

要检查Rails的命名约定,topfunky的Pluralizer是有益的。

回答by igor

there is a new syntaxis for Rails is rails generate

Rails 有一个新的语法是 rails generate