Rails scaffold_controller 生成器不会将模型属性应用于视图 [英] Rails scaffold_controller generator doesn't apply model attributes to views

查看:29
本文介绍了Rails scaffold_controller 生成器不会将模型属性应用于视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在具有现有属性的现有模型上使用 scaffold_controller 生成器,但是生成的视图表单没有对应模型属性的任何输入控件 - 它们只是空表单.这是为什么?

I'm using the scaffold_controller generator on an existing model with existing attributes, but the view forms that get generated don't have any input controls for the corresponding model attributes - they're just empty forms. Why is that?

例如:

rails generate scaffold_controller User --skip --no-test-framework

如果用户已经具有 nameemail 属性,则应生成带有姓名和电子邮件字段的表单...

Where the User already has name and email attributes should generate forms with name and email fields...

推荐答案

这就是它应该做的.当调用 scaffold_controller 时,你告诉生成器不要使用模型.如果你想在视图中包含表单属性,你需要像传递普通脚手架一样将它们传递给生成器.

This is what it is supposed to do. When calling scaffold_controller you're telling the generator to not use a model. If you want to have form attributes in the views, you need to pass them to the generator just like you would a normal scaffolding.

rails g scaffold_controller User name email

这篇关于Rails scaffold_controller 生成器不会将模型属性应用于视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆