gpt4 book ai didi

ruby-on-rails - Rails 创建新的 MVC

转载 作者:数据小太阳 更新时间:2023-10-29 08:39:03 25 4
gpt4 key购买 nike

我想创建一个名为 models/thing.rb 的模型,一个名为 controllers/things_controller.rb 的 Controller ,以及一个名为 views/things/的 View index.html.erbviews/things/hello.html.erb

我如何从 Rails 控制台执行此操作?我知道我必须使用 rails generate

最佳答案

首先用indexhello两个action生成controller。

rails g controller things index hello

此命令将使用 views/things/index.html.erbviews/things/hello.html.erb 生成 Controller 和 View 。

然后生成模型:

rails g model Thing 属性:type [...]

如果您想了解更多关于 rails generate 命令的信息,可以查看 A Guide to The Rails Command Line

关于ruby-on-rails - Rails 创建新的 MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16001444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com