自动为 Rails 3 中的现有数据库方案生成脚手架
我有现有的数据库,我想自动生成控制器和视图,以包含具有字段大小和非空验证的模型。我研究了一个名为“魔法模型生成器”的项目,但它看起来很旧,并且只能根据我所知创建模型。
我希望这主要是为了节省时间,并且我知道大多数控制器和视图对于面向用户的功能来说没有用处。我将剔除不需要的内容并将其中大部分移至管理页面。
有一个工具可以做到这一点吗?
蒂亚!
编辑:我想创建实际文件并且不需要动态管理。我将使用控制器和视图来查看网站的一些正面部分。
I have existing database that I would like to auto generate the controllers and views for including models with field size and not null validation. I looked into a project called the Magic Model Generator but it looked old and only creates models from what I can tell.
I want this as primarily a time saver and I understand that most of the controllers and views will not be useful for user facing functionally. I will be plucking out what I don't need and moving most of it to administration pages.
Is there a tool for doing this?
TIA!
Edit: I want to create the actual files and do not want a dynamic admin. I will be using the controllers and view for some front facing parts of the site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不确定是否适用于 Rails 3,但适用于 Rails 4!
下面的步骤教授如何从现有数据库构建模型、表单、控制器等。
希望有帮助!
Not sure if works for Rails 3, but does for Rails 4!
Steps below teaches how to build your models, forms, controllers and etc from a existing database.
Hope it helps!
我相信这个问题在这里得到了解答:
当模型已经存在时如何运行`rails生成脚手架`?
在这里:
现有模型和数据库表的rails g脚手架
简短的答案是(例如模型=帖子)
I believe this question is answered here:
How to run `rails generate scaffold` when the model already exists?
and here:
rails g scaffold for existing model and DB table
with the short answer being (e.g. model = Post)
RailsAdmin gem
https://github.com/sferik/rails_admin
RailsAdmin gem
https://github.com/sferik/rails_admin
我认为你可以用它来解决你的部分问题。将 Rails 应用程序指向旧数据库后,执行 rake db:schema:dump 您可以使用名为 schema_to_scaffold 生成脚手架脚本。
输出:
rails gscaffold users fname:string lname:string bdate:date email:string generated_password:string
它从您的 schema.rb 和您重命名的 schema.rb 中 。检查此处
I think you can use this to solve part of your problem. After pointing your rails app to your old database then do a rake db:schema:dump you can use a gem called schema_to_scaffold to generate a scaffold script.
It outputs:
rails g scaffold users fname:string lname:string bdate:date email:string encrypted_password:string
from your schema.rb our your renamed schema.rb. Check here