简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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