-
Notifications
You must be signed in to change notification settings - Fork 8
Create a Scaffold
Alexey Gordeyev edited this page Jan 19, 2014
·
21 revisions
How to create Scaffold via CLI TrinteJS MVC
format: trinte -g crud [scaffold name] [field(s)]
// Creates all (model, views, controller, tests)
$ trinte -g crud User
// create Post model and etc. with fields: title, content, created, active
$ trinte -g crud Post title content created:date active:boolean
- See all valid field types here.
Generated files, path like that:
.
|
`-- app
|-- models
| `-- Post.js
`-- controllers
| `-- PostsController.js
`-- views
`-- posts
|-- form.ejs
|-- edit.ejs
|-- new.ejs
|-- index.ejs
`-- show.js
Add routes in /config/routes.js
map.resources('posts');will provide the following routes:
method route controller#action helper method
--------------------------------------------------------------------------
GET /posts posts#index pathTo.posts()
GET /posts/:id posts#show pathTo.show_post(post)
POST /posts posts#create pathTo.create_posts()
GET /posts/new posts#new pathTo.new_post()
GET /posts/edit/:id posts#edit pathTo.edit_post(post)
DELETE /posts/:id posts#destroy pathTo.destroy_post(post)
PUT /posts/:id posts#update pathTo.update_post(post)
DELETE /posts posts#destroyall pathTo.destroy_posts()
// create Post model and etc. with fields: title, message, active
$ trinte g crud admin#Post title message active:boolean
Generated files, path like that:
.
|
`-- app
|-- models
| `-- Post.js
|-- controllers
| `-- admin
| `-- PostsController.js
`-- views
`-- admin
`-- posts
|-- form.ejs
|-- edit.ejs
|-- new.ejs
|-- index.ejs
`-- show.js
Add routes in /config/routes.js
map.namespace('admin', function(admin){
admin.resources("posts");
});will provide the following routes:
method route controller#action helper method
---------------------------------------------------------------------------------
GET /admin/posts admin/posts#index pathTo.admin_posts()
GET /admin/posts/:id admin/posts#show pathTo.show_admin_post(post)
POST /admin/posts admin/posts#create pathTo.create_admin_posts()
GET /admin/posts/new admin/posts#new pathTo.new_admin_post()
GET /admin/posts/edit/:id admin/posts#edit pathTo.edit_admin_post(post)
DELETE /admin/posts/:id admin/posts#destroy pathTo.destroy_admin_post(post)
PUT /admin/posts/:id admin/posts#update pathTo.update_admin_post(post)
DELETE /admin/posts admin/posts#destroyall pathTo.destroy_admin_posts()