1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

update the scaffold generator outputs

This commit is contained in:
Akira Matsuda 2013-01-04 05:14:24 +09:00
parent 8572f32d58
commit 2161434d16
2 changed files with 16 additions and 5 deletions

View file

@ -225,6 +225,7 @@ $ rails generate scaffold HighScore game:string score:integer
invoke test_unit invoke test_unit
create test/models/high_score_test.rb create test/models/high_score_test.rb
create test/fixtures/high_scores.yml create test/fixtures/high_scores.yml
invoke resource_route
route resources :high_scores route resources :high_scores
invoke scaffold_controller invoke scaffold_controller
create app/controllers/high_scores_controller.rb create app/controllers/high_scores_controller.rb

View file

@ -176,6 +176,7 @@ $ rails generate scaffold User name:string
invoke test_unit invoke test_unit
create test/models/user_test.rb create test/models/user_test.rb
create test/fixtures/users.yml create test/fixtures/users.yml
invoke resource_route
route resources :users route resources :users
invoke scaffold_controller invoke scaffold_controller
create app/controllers/users_controller.rb create app/controllers/users_controller.rb
@ -192,8 +193,13 @@ $ rails generate scaffold User name:string
create app/helpers/users_helper.rb create app/helpers/users_helper.rb
invoke test_unit invoke test_unit
create test/helpers/users_helper_test.rb create test/helpers/users_helper_test.rb
invoke stylesheets invoke assets
create app/assets/stylesheets/scaffold.css invoke coffee
create app/assets/javascripts/users.js.coffee
invoke scss
create app/assets/stylesheets/users.css.scss
invoke scss
create app/assets/stylesheets/scaffolds.css.scss
``` ```
Looking at this output, it's easy to understand how generators work in Rails 3.0 and above. The scaffold generator doesn't actually generate anything, it just invokes others to do the work. This allows us to add/replace/remove any of those invocations. For instance, the scaffold generator invokes the scaffold_controller generator, which invokes erb, test_unit and helper generators. Since each generator has a single responsibility, they are easy to reuse, avoiding code duplication. Looking at this output, it's easy to understand how generators work in Rails 3.0 and above. The scaffold generator doesn't actually generate anything, it just invokes others to do the work. This allows us to add/replace/remove any of those invocations. For instance, the scaffold generator invokes the scaffold_controller generator, which invokes erb, test_unit and helper generators. Since each generator has a single responsibility, they are easy to reuse, avoiding code duplication.
@ -350,6 +356,7 @@ $ rails generate scaffold Comment body:text
invoke shoulda invoke shoulda
create test/models/comment_test.rb create test/models/comment_test.rb
create test/fixtures/comments.yml create test/fixtures/comments.yml
invoke resource_route
route resources :comments route resources :comments
invoke scaffold_controller invoke scaffold_controller
create app/controllers/comments_controller.rb create app/controllers/comments_controller.rb
@ -360,13 +367,16 @@ $ rails generate scaffold Comment body:text
create app/views/comments/show.html.erb create app/views/comments/show.html.erb
create app/views/comments/new.html.erb create app/views/comments/new.html.erb
create app/views/comments/_form.html.erb create app/views/comments/_form.html.erb
create app/views/layouts/comments.html.erb
invoke shoulda invoke shoulda
create test/controllers/comments_controller_test.rb create test/controllers/comments_controller_test.rb
invoke my_helper invoke my_helper
create app/helpers/comments_helper.rb create app/helpers/comments_helper.rb
invoke shoulda invoke shoulda
create test/helpers/comments_helper_test.rb create test/helpers/comments_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/comments.js.coffee
invoke scss
``` ```
Fallbacks allow your generators to have a single responsibility, increasing code reuse and reducing the amount of duplication. Fallbacks allow your generators to have a single responsibility, increasing code reuse and reducing the amount of duplication.