Ruby on Rails Generating Views

前端 未结 4 988
名媛妹妹
名媛妹妹 2021-01-31 13:52

Is there a way to generate the views separately using the rails generate command? I would also be willing to install a gem to accomplish that task f one exists. Basically the sc

4条回答
  •  一生所求
    2021-01-31 14:16

    One particular situation is when you want to add a new view to an existing controller.

    In that case, just use the regular command, but be careful to say 'n' every time prompted in order to not overwrite existing files.

    For example, adding a view called 'invite' to an existing controller named 'projects':

    smith@ubuntuSrv16DEV4:~/railsapps/project_manager$ rails -v
    Rails 5.1.4
    smith@ubuntuSrv16DEV4:~/railsapps/project_manager$ rails generate controller projects invite
    Running via Spring preloader in process 46253
        conflict  app/controllers/projects_controller.rb
    Overwrite /home/smith/railsapps/project_manager/app/controllers/projects_controller.rb? (enter "h" for help) [Ynaqdh] n
            skip  app/controllers/projects_controller.rb
           route  get 'projects/invite'
          invoke  erb
           exist    app/views/projects
          create    app/views/projects/invite.html.erb
          invoke  test_unit
        conflict    test/controllers/projects_controller_test.rb
      Overwrite /home/smith/railsapps/project_manager/test/controllers/projects_controller_test.rb? (enter "h" for help) [Ynaqdh] n
            skip    test/controllers/projects_controller_test.rb
          invoke  helper
       identical    app/helpers/projects_helper.rb
          invoke    test_unit
          invoke  assets
          invoke    coffee
       identical      app/assets/javascripts/projects.coffee
          invoke    scss
        conflict      app/assets/stylesheets/projects.scss
        Overwrite /home/smith/railsapps/project_manager/app/assets/stylesheets/projects.scss? (enter "h" for help) [Ynaqdh] n
            skip      app/assets/stylesheets/projects.scss
    smith@ubuntuSrv16DEV4:~/railsapps/project_manager$ 
    

提交回复
热议问题