Ruby On Rails: Create Models View And Controller from existing database
You have to create simple model for every table with relations, and then you can
[rails3] > rails generate scaffold_controller Club name:string exclusive:boolean create app/controllers/clubs_controller.rb invoke erb create app/views/clubs create app/views/clubs/index.html.erb create app/views/clubs/edit.html.erb create app/views/clubs/show.html.erb create app/views/clubs/new.html.erb create app/views/clubs/_form.html.erb create app/views/layouts/clubs.html.erb invoke test_unit create test/functional/clubs_controller_test.rb
Alternatively you can try active_admin gem
ActiveAdmin - https://github.com/gregbell/active_admin
rails generate active_admin:resource [MyModelName]
RailsAdmin is also good enough https://github.com/sferik/rails_admin
You should specify at least 2 rules for your model if it doesn't use rails conventions.Example
class Article < ActiveRecord::Base self.table_name "tbl_articles" self.primary_key "art_id"end
Well this goes against principles. The better you have to do, if you want a quick bootstrap for your application is replicate the models you have on your database and use scaffolding.Remember that Rails use a LOT of conventions, and if you decide not follow you'll have a lot of trouble.
Check this guide if you need help.
This is how you can do that -
Try:
rails g scaffold myscaffold
This will generate the files:
invoke active_recordcreate db/migrate/20130124100759_create_myscaffolds.rbcreate app/models/myscaffold.rbinvoke test_unitcreate test/unit/myscaffold_test.rbcreate test/fixtures/myscaffolds.yml route resources :myscaffoldsinvoke scaffold_controllercreate app/controllers/myscaffolds_controller.rbinvoke erbcreate app/views/myscaffoldscreate app/views/myscaffolds/index.html.erbcreate app/views/myscaffolds/edit.html.erbcreate app/views/myscaffolds/show.html.erbcreate app/views/myscaffolds/new.html.erbcreate app/views/myscaffolds/_form.html.erbinvoke test_unitcreate test/functional/myscaffolds_controller_test.rbinvoke helpercreate app/helpers/myscaffolds_helper.rbinvoke test_unitcreate test/unit/helpers/myscaffolds_helper_test.rbinvoke assetsinvoke coffeecreate app/assets/javascripts/myscaffolds.js.coffeeinvoke scsscreate app/assets/stylesheets/myscaffolds.css.scssinvoke scssidentical app/assets/stylesheets/scaffolds.css.scss