您的位置:首页 > 大数据 > 人工智能

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.

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.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: