我正试图生成一些模型,但它们正在生成没有属性。
我使用的是Linux系统,rails版本是:rails --version Rails 4.0.0
我试图用这个命令生成模型:
rails g scaffold Bsdsd description:string test:string oaso:integer和
rails g model Asdsd description:string test:string oaso:integer在这个空的类模型中的第一个结果一切正常:
class Bsdsd < ActiveRecord::Base end第二个结果是测试文件,迁移文件(包含属性)和这个类模型:
class Asdsd < ActiveRecord::Base end我怎样才能纠正这种行为?
I'm trying to generate some models but they are being generated without attributes.
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:integerand
rails g model Asdsd description:string test:string oaso:integerThe first results in this empty class model everything else ok:
class Bsdsd < ActiveRecord::Base endThe second results in test files, migrations file(that contains the attributes) and this class model:
class Asdsd < ActiveRecord::Base endHow can I correct this behavior?
最满意答案
模型属性是从数据库列中推断出来的,因此您不需要在模型类中指定它们。
在Rails 3.2中,如果我没有记错,
# attr_accessible :description, :test, :oaso生成的线。 但受保护的属性在Rails 4.0中已被弃用,并被强参数机制所取代。
Model attributes are inferred from database columns, so you don't need them specified in model classes.
In Rails 3.2 you had (if I remember correctly)
# attr_accessible :description, :test, :oasoline generated. But protected attributes are deprecated in Rails 4.0 and replaced by strong parameters mechanism.
更多推荐
发布评论