为什么 rails 生成空模型? [英] Why rails is generating empty models?
问题描述
我正在尝试生成一些模型,但它们是在没有属性的情况下生成的.
I'm trying to generate some models but they are being generated without attributes.
我使用的是 linux 系统,rails 版本是:导轨 --version导轨 4.0.0
I'm using a linux system and the rails version is: rails --version Rails 4.0.0
我尝试使用以下命令生成模型:
I've tried to generate the models using this commands:
rails g scaffold Bsdsd description:string test:string oaso:integer
和
rails g model Asdsd description:string test:string oaso:integer
第一个结果在这个空的类模型中,其他一切正常:
The first results in this empty class model everything else ok:
class Bsdsd < ActiveRecord::Base
end
第二个结果是测试文件、迁移文件(包含属性)和这个类模型:
The second results in test files, migrations file(that contains the attributes) and this class model:
class Asdsd < ActiveRecord::Base
end
我该如何纠正这种行为?
How can I correct this behavior?
推荐答案
模型属性是从数据库列中推断出来的,因此您不需要在模型类中指定它们.
Model attributes are inferred from database columns, so you don't need them specified in model classes.
在 Rails 3.2 中你有(如果我没记错的话)
In Rails 3.2 you had (if I remember correctly)
# attr_accessible :description, :test, :oaso
行生成.但是受保护的属性在 Rails 4.0 中已被弃用,取而代之的是强参数机制.
line generated. But protected attributes are deprecated in Rails 4.0 and replaced by strong parameters mechanism.
这篇关于为什么 rails 生成空模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!