So as my first entry of this series (whether I'm making this series or not) I put how I tested scaffold in this time. Scaffold is the simplest way creating M-V-C app. We just need to specify a table as model. Controller (list, new, edit, and delete) and Views (which is the presentation layer of app) are created automatically. So, let me start!
- Start Instant Rails by clicking the Icon or whatever
- Open a Terminal from Instant Rails
(click [I]->Rails Applications -> Manage Rails Applications, and click "Create New Rails App..." button at the bottom of the new window. - In the Terminal, type
rails -d mysql app_name
... like rails -d mysql namelist
This creates a batch of files under app_name - check
\config/database.yml for connection to DB.
Notepad doesn't quite work, so use another text editor. (I'm using ConTEXT as my professor recommended.)
- In the Terminal,
cd app_name .......... entering app dir
rake db:create ........ create database named app_name_development - In the Terminal,
ruby script\generate scaffold table_name col_name:type...
... like ruby script\generate scaffold user name:string contact:string
Technically, this creates a model which is actually a table in DB. - In the Terminal,
rake db:migrate ................ This creates the table in DB
You can check it by entering mysql from another Terminal
(show databases, use database, show tables are a few of mysql commands.) - In Managing Rails App Window,
click refresh, check your app, and click start with Morgel
This starts your app. - To test your app, in a browser, go to;
http://localhost:3000/table name/new
... like http://localhost:3000/users/new
I saw a couple of errors from Ruby console window being created as the app started. But after reloading the URL a few times, it went through.
No comments:
Post a Comment