Generate a controller with all the RESTful functions

前端 未结 10 1487
遇见更好的自我
遇见更好的自我 2021-01-30 07:58

I am trying to generate a controller with all the RESTful actions stubbed. I had read at Wikibooks - Ruby on Rails that all I needed to do was to call the generator with the co

10条回答
  •  感情败类
    2021-01-30 08:42

    Rails 5.1

    Starting point:

    You have created a model without a controller, nor views (eg thru: rails generate model category)

    Objective:

    Upgrade it to a full RESTful resource

    Command:

    rails generate scaffold_controller category

    It stubs out a scaffolded controller, its seven RESTful actions and related views. (Note: You can either pass the model name CamelCased or under_scored.)

    Output:

    varus@septimusSrv16DEV4:~/railsapps/dblirish$ rails generate scaffold_controller category
    Running via Spring preloader in process 45681
          create  app/controllers/categories_controller.rb
          invoke  erb
          create    app/views/categories
          create    app/views/categories/index.html.erb
          create    app/views/categories/edit.html.erb
          create    app/views/categories/show.html.erb
          create    app/views/categories/new.html.erb
          create    app/views/categories/_form.html.erb
          invoke  test_unit
          create    test/controllers/categories_controller_test.rb
          invoke  helper
          create    app/helpers/categories_helper.rb
          invoke    test_unit
          invoke  jbuilder
          create    app/views/categories/index.json.jbuilder
          create    app/views/categories/show.json.jbuilder
          create    app/views/categories/_category.json.jbuilder
    

提交回复
热议问题