Ruby on Rails生成模型field:type-field:type的选项是什么? [英] Ruby on Rails generates model field:type - what are the options for field:type?

查看:83
本文介绍了Ruby on Rails生成模型field:type-field:type的选项是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图生成一个新模型,却忘记了引用另一个模型ID的语法.我会自己查一下,但是在我所有的Ruby on Rails文档链接中,我还没有弄清楚如何找到确定的源代码.

I'm trying to generate a new model and forget the syntax for referencing another model's ID. I'd look it up myself, but I haven't figured out, among all my Ruby on Rails documentation links, how to find the definitive source.

$ rails g model Item name:string description:text(此处为reference:productreferences:product).但是更好的问题是,在哪里 我将来如何可以轻松地找到这种愚蠢的东西?

$ rails g model Item name:string description:text (and here either reference:product or references:product). But the better question is where or how can I look for this kind of silliness easily in the future?

注意:我已经学到了很难的方法,如果我输错了这些选项之一并运行迁移,那么Ruby on Rails将完全破坏我的数据库...而rake db:rollback却无能为力反对这样的搞砸.我敢肯定我只是不了解某些东西,但是直到我明白... rails g model返回的详细"信息仍然让我抓不住...

Note: I've learned the hard way that if I mistype one of these options and run my migration then Ruby on Rails will totally screw up my database... and rake db:rollback is powerless against such screwups. I'm sure I'm just not understanding something, but until I do... the "detailed" information returned by rails g model still leaves me scratching...

推荐答案

:primary_key, :string, :text, :integer, :float, :decimal, :datetime, :timestamp,
:time, :date, :binary, :boolean, :references

请参见表定义部分.

这篇关于Ruby on Rails生成模型field:type-field:type的选项是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆