简体   繁体   English

Ruby on Rails-生成脚手架命令中的模型

[英]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.

相关问题 Ruby on Rails-有没有办法从数据库表生成脚手架脚本? - Ruby on Rails - Is there a way to generate a scaffold script from database tables? 导轨会生成支架,但会阻止生成模型文件 - rails generate scaffold but prevent the model file from being generated 在轨道上使用红宝石创建联合表的推荐方法:轨道生成支架,轨道生成模型或轨道生成迁移? - Recommended way to create a joint table using ruby on rails: rails generate scaffold, rails generate model, or rails generate migration? 滑轨生成支架不会生成模型 - Running rails generate scaffold does not generate model 红宝石rvm导轨生成支架失败 - ruby rvm rails generate scaffold fails Windows上的rails生成scaffold命令导致ArgumentError - rails generate scaffold command on Windows causes ArgumentError Ruby on Rails脚手架模型验证问题 - Ruby on rails scaffold model validation questions 链接从“ rails generate Scaffold”生成的两个表(Ruby on Rails的新增功能) - Linking two tables generated from “rails generate Scaffold” (New to Ruby on Rails) 轨道上的红宝石不会生成模型 - ruby on rails will not generate model Rails 7 不会在 `generate scaffold` 命令上生成 SCSS 文件 - Rails 7 doesn’t generate SCSS file on the `generate scaffold` command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM