Why does Rails 4 scaffold create json.jbuilder files?

后端 未结 4 496
走了就别回头了
走了就别回头了 2021-02-01 14:57

I\'ve generated a new rails 4 (rc1) project using rails new and generated a scaffold using rails g scaffold.

As expected it has created the mi

4条回答
  •  粉色の甜心
    2021-02-01 15:36

    To answer the "why" part:

    The relevance of scaffolding in Rails has somewhat shifted over the years. It is no longer meant to generate necessary code which couldn't be abstracted away easily. Today it is mostly an educational tool to provide you with a somewhat dynamic example and demonstrate best practices. (That's also the reason why they are sprinkled with comments with disputable usefulness)

    In other words the generated files are meant to tell you:

    If you are going to use Rails, here is a good way how you could do it.

    or in your specific case:

    If you are going to use JBuilder, here is a good way to generate JSON.

    They are not meant to tell: "This is how it must be done." or "You have to keep all the generated stuff because it's necessary."

提交回复
热议问题