ハロの外部記憶インターフェイス

そろそろ覚える努力が必要かも…

Scaffold Model作成

Scaffoldによって作成される場合、自動でモデルとコントローラが作成される

$ rails generate scaffold myProduct
      invoke  active_record
      create    db/migrate/20130609073950_create_my_products.rb
      create    app/models/my_product.rb
      invoke    test_unit
      create      test/unit/my_product_test.rb
      create      test/fixtures/my_products.yml
      invoke  resource_route
       route    resources :my_products
      invoke  scaffold_controller
      create    app/controllers/my_products_controller.rb
      invoke    erb
      create      app/views/my_products
      create      app/views/my_products/index.html.erb
      create      app/views/my_products/edit.html.erb
      create      app/views/my_products/show.html.erb
      create      app/views/my_products/new.html.erb
      create      app/views/my_products/_form.html.erb
      invoke    test_unit
      create      test/functional/my_products_controller_test.rb
      invoke    helper
      create      app/helpers/my_products_helper.rb
      invoke      test_unit
      create        test/unit/helpers/my_products_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/my_products.js.coffee
      invoke    scss
      create      app/assets/stylesheets/my_products.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss
  1. my_productsコントローラが作成されている
  2. my_productモデルが作成されている
  3. app/views/my_productsにテンプレートが作成されている

DB作成

$ rake db:migrate
 rake db:migrate
==  CreateMyProducts: migrating ===============================================
 create_table(:my_products)
   -> 0.0016s
==  CreateMyProducts: migrated (0.0020s) ======================================

確認

$rails server
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-06-09 16:49:39] INFO  WEBrick 1.3.1
[2013-06-09 16:49:39] INFO  ruby 1.8.7 (2012-02-08) [universal-darwin12.0]
[2013-06-09 16:49:39] INFO  WEBrick::HTTPServer#start: pid=1087 port=3000
  1. localhost:3000/my_productsで確認が可能になる