Reputation: 28121
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.
Upvotes: 7
Views: 14085
Reputation: 376
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!
Upvotes: 19
Reputation: 703
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
Upvotes: 3
Reputation: 11706
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)
rails generate scaffold_controller Post
Upvotes: 4