简体   繁体   English

如何在Rails 4上生成模型字段?

[英]How to generate model fields on rails 4?

I have run 我跑了

rails generate Model Profile name:string

It have worked and generated all the files. 它已经工作并生成了所有文件。 When I see the profile.rb file though it only has the class declaration not the fields. 当我看到profile.rb文件时,尽管它仅具有类声明,但没有字段。

class Profile < ActiveRecord::Base
end

Do I have to add all the fields manually ? 我是否必须手动添加所有字段?

No, you don't to add fields manually. 不,您不必手动添加字段。 ActiveRecord will discover them at runtime from the table structure. ActiveRecord将在运行时从表结构中发现它们。 This is part of rails magic :) 这是Rails Magic的一部分:)

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

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