Why does Rails 4 scaffold create json.jbuilder files?

后端 未结 4 491
走了就别回头了
走了就别回头了 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:40

    As said before, Rails 4 seems to generate the files as a way to have a template for responding to a JSON query. So let's say you have "scaffolded" a model Car, then it will respond with a HTML page and a detail view of car (id 1) if you go /car/1.

    Then if you go to /car/1.json, it will render the show.json.jbuilder file. There also seems to be some kind of automatic mechanism as the show method is empty when scaffolding:

    def show
    end
    

提交回复
热议问题