How does these rails generate command differ? and what basically rails generate means?
rails generate migration rails generate model rails generate scaffold rails generate 开发者_如何学JAVAcontroller etc.
How these differ?According to rails guides:
Using generators will save you a large amount of time by writing boilerplate code, code that is necessary for the app to work, but not necessary for you to spend time writing. That’s what we have computers for.
rails generate
commands family used to provide simple and easy way for developer to create different object types.
rails generate migration
- creates DB migration script in db/migrations
directory so developer can setup his DB.
rails generate model
- creates model class with associated migration, test and fixtures (test data).
rails generate scaffold
- creates all nedded classes with basic logic and presentaion. It creates controller (with simple CRUD logic), model, fixtures, functional and unit tests.
rails generate controller
- creates controller with associated functional tests, helper and basic views templates.
You can read more here: http://guides.rubyonrails.org/command_line.html#rails-generate
They differ in the sense that they generate different stuff.
migration will generate a database migration file, model will generate a model(with a migration and a spec by default) scaffold will generate a scaffold of a resource and controller will generate a controller.
generate means it will create the files for you with boiler plate code already in place(you will still need to edit them though..but scaffold can get you working with a basic application already)
Read more about it here: http://guides.rubyonrails.org/command_line.html#rails-generate
rails generate
is a command line script for quickly generating the code for various Rails' constructs.
In the example you give they differ by what they produce, with the first argument being the type of code generated. For example if I wanted to create a User
model I would run:
`rails generate model user`
The model file, test file and migration would be created for me.
You should read the Rails' documentation to find more.
**rails generate model user:
The above command create a Template Object that is a mirror image of the database table. For example, if you have a database table that is named users that has a name:string, and email:string field,then "rails generate model user" create an Object that mirrors that user table with a few addition.
Here are the similarity they both have name:string,email:string the both have the word user. The difference are few but significant: user is Capitalized in the model name like "User". The Table add create_by and updated_by automatically.
migration:db create the database mirror using the model as a model.RECURSION ANYONE?
精彩评论