user3064141
user3064141

Reputation: 407

Ruby on Rails - model from generate scaffold command

I used "rails generate scaffold Post title:string body:text" to create a model and related controller etc. I was surprised to find the model and controller files empty. I thought the model file would contain instance variables to store each post's title and body attributes. Can someone explain to me why the Post model file running generate scaffold is empty even though the data items do show up in the database. When I bring up the webpage and go to the .../posts url I can see the json listing of the ones I created. Thanks.

Upvotes: 1

Views: 327

Answers (1)

hashrocket
hashrocket

Reputation: 2222

Models are Ruby classes. They talk to the database, store and validate data, perform the business logic and otherwise do the heavy lifting.

Controllers do the work of parsing user requests, data submissions, cookies, sessions and the “browser stuff”.

The reason your model is empty is because Rails doesn't know what you want your models to do. It knows you want basic CRUD functionality, so it fills in your controllers accordingly.

Upvotes: 2

Related Questions