Generate a controller with all the RESTful functions

前端 未结 10 1567
遇见更好的自我
遇见更好的自我 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:46

    One solution is to create a script that accepts one parameter, the controller name, and let the script type the whole command for you.


    1. Create a new file, say, railsgcontroller
    2. Make it executable and save it on path
    3. Run it like: $ railsgcontroller Articles

    die () {
        echo "Please supply new rails controller name to generate."
        echo >&2 "$@"
        exit 1
    }
    
    [ "$#" -eq 1 ] || die "1 argument required, $# provided"
    
    rails g controller "$1" new create update edit destroy show index
    

提交回复
热议问题