rails ruby 中不同类型的模型字段?

Different types of Model fields in ruby on rails?

我在 rails 中创建了一个模型,我需要一些与模型的每个实例相关的日期和时间属性。我无法找到 rails 提供的所有类型的字段,例如字符串、布尔值、文本等?有人可以为此提供 link 吗,这会很有帮助。

要查看有关模型的可用帮助,您可以 运行 命令 rails g model。 命令和模型有很多细节。这是关于字段类型的摘录,希望对您有所帮助。

Available field types:

Just after the field name you can specify a type like text or boolean.
It will generate the column with the associated SQL type. For instance:

    `rails generate model post title:string body:text`

will generate a title column with a varchar type and a body column with a text
type. If no type is specified the string type will be used by default.
You can use the following types:

    integer
    primary_key
    decimal
    float
    boolean
    binary
    string
    text
    date
    time
    datetime

You can also consider `references` as a kind of type. For instance, if you run:

    `rails generate model photo title:string album:references`

It will generate an `album_id` column. You should generate these kinds of fields when
you will use a `belongs_to` association, for instance. `references` also supports
polymorphism, you can enable polymorphism like this:

    `rails generate model product supplier:references{polymorphic}`

For integer, string, text and binary fields, an integer in curly braces will
be set as the limit:

    `rails generate model user pseudo:string{30}`

For decimal, two integers separated by a comma in curly braces will be used
for precision and scale:

    `rails generate model product 'price:decimal{10,2}'`