rails 命令行,学习心得,原作
2010-11-01 15:55
453 查看
rails g controller Product action1 action2
The controller generator is expecting parameters in the form of generate controller ControllerName action1 action2. Let’s make a Greetings controller with an action of hello, which will say something nice to us.
What all did this generate? It made sure a bunch of directories were in our application, and created a controller file, a functional test file, a helper for the view, and a view file.
instead of generating a model directly (which we’ll be doing later), let’s set up a scaffold. A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.
The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the high_scores table and fields), takes care of the route for the resource, and new tests for everything.
The controller generator is expecting parameters in the form of generate controller ControllerName action1 action2. Let’s make a Greetings controller with an action of hello, which will say something nice to us.
What all did this generate? It made sure a bunch of directories were in our application, and created a controller file, a functional test file, a helper for the view, and a view file.
rails generate model ModelName [field:type, field:type] 生成一个model往数据库迁移的文件 生成一个model的空类文件 生成两个测试用的文件
instead of generating a model directly (which we’ll be doing later), let’s set up a scaffold. A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.
$ rails generate scaffold HighScore game:string score:integer
The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the high_scores table and fields), takes care of the route for the resource, and new tests for everything.
相关文章推荐
- Ruby on Rails学习心得(四)数据库外键和迁移
- Ruby on Rails学习心得(二)Hello Ruby on Rails
- linux命令行参数解析学习心得
- Ruby on Rails学习心得(一)配置Ruby on Rails
- 命令行PowerShell学习心得
- Ruby on Rails学习心得(三)数据库基本操作
- java IO学习心得
- MPEG-2标准学习心得
- 学习过程中一些心得
- windows 服务程序学习心得
- LeetCode编程练习 - Move Zeroes学习心得
- 命令行(DOS命令)学习笔记
- ckeditor的配置以及学习心得
- java Struts 学习心得(中文乱码)
- 学习心得——从静态成员看类的抽象性
- 谈一谈学习AngularJS2的一些package的心得
- 文献管理软件CNKI E-study学习心得
- Mygui例子学习心得
- eclipse debug (调试) 学习心得
- VC++学习心得系列