[英]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. 我使用“ rails generate scaffold post title:string body:text”创建模型和相关控制器等。我很惊讶地发现模型和控制器文件为空。 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. 有人可以向我解释为什么运行的Post模型文件生成的脚手架为空,即使数据项确实显示在数据库中也是如此。 When I bring up the webpage and go to the .../posts url I can see the json listing of the ones I created. 当我打开网页并转到... / posts网址时,我可以看到我创建的内容的json列表。 Thanks. 谢谢。
Models are Ruby classes. 模型是Ruby类。 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”. 控制器负责解析用户请求,数据提交,cookie,会话和“浏览器内容”。
The reason your model is empty is because Rails doesn't know what you want your models to do. 您的模型为空的原因是,Rails不知道您想让模型做什么。 It knows you want basic CRUD functionality, so it fills in your controllers accordingly. 它知道您需要基本的CRUD功能,因此它会相应地填充您的控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.