Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why rails is generating empty models?

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:integer

and

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?

like image 720
Alexandre Avatar asked Jan 13 '23 03:01

Alexandre


1 Answers

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, :oaso

line generated. But protected attributes are deprecated in Rails 4.0 and replaced by strong parameters mechanism.

like image 190
Marek Lipka Avatar answered Jan 21 '23 09:01

Marek Lipka