Skip JSON format in rails generate scaffold

前端 未结 4 1305
南旧
南旧 2021-02-07 01:29

When you generate a rails scaffold using a command like rails g scaffold Thing is there any way to avoid getting that annoying

respond_to do |format         


        
4条回答
  •  走了就别回头了
    2021-02-07 02:17

    I think you'd be missing an opportunity. For one thing, you'd be teaching non-standard Rails, so your students might be confused when they see the normal version in their own installations.

    More importantly, the controllers are formatted that way for a reason. Rails puts an emphasis on REST, which encourages access to resources via multiple data formats. Many modern apps are de-emphasizing slower server-rendered html/erb responses in favor of json APIs. I realize this is a little over a year after your OP, and you have limited time in class, just adding some thoughts for anyone who might happen by. I think you could wave your hand over the respond_to and tell them it's setting you up for some future possibilities.

提交回复
热议问题