コントローラとモデルがすでに作成された後に、Ruby on Rails ビュー(のみ)を作成する 質問する

コントローラとモデルがすでに作成された後に、Ruby on Rails ビュー(のみ)を作成する 質問する

コントローラー (最小限のコードのみ) とモデルを含むプロジェクトを取得しましたが、ビューがありません。scaffold または別のツールを使用してビューのみを生成する方法はありますか?

ベストアンサー1

rails g scaffold User --migration=false --skip

すでに存在するファイルをスキップする手段--skipです。(反対は です--force。)

ヘルパーが必要ない場合は、--helpers=false.

ビューを削除した後のサンプル出力User:

      invoke  active_record
   identical    app/models/user.rb
      invoke    test_unit
   identical      test/unit/user_test.rb
        skip      test/fixtures/users.yml
       route  resources :users
      invoke  scaffold_controller
   identical    app/controllers/users_controller.rb
      invoke    erb
       exist      app/views/users
      create      app/views/users/index.html.erb
      create      app/views/users/edit.html.erb
      create      app/views/users/show.html.erb
      create      app/views/users/new.html.erb
      create      app/views/users/_form.html.erb
      invoke    test_unit
   identical      test/functional/users_controller_test.rb
      invoke    helper
   identical      app/helpers/users_helper.rb
      invoke      test_unit
   identical        test/unit/helpers/users_helper_test.rb
      invoke  assets
      invoke    coffee
   identical      app/assets/javascripts/users.js.coffee
      invoke    scss
   identical      app/assets/stylesheets/users.css.scss
      invoke  scss
   identical    app/assets/stylesheets/scaffolds.css.scss

おすすめ記事