Current scaffold_controller generates old code with lots of cruft. Changed to use respond_to and respond_with instead of the huge format blocks.
Removed comments from scaffold_controller
Updated scaffold_controller generator to use respond_to and
respond_with (ht: radar)
I helped Breccan with this one.
We both (and other people I've talked to) think the people using scaffolding would really appreciate it if there was less code that was generated when a scaffold was run. Currently, the scaffold generator hasn't changed much at all since 2.3 and still contains the ugly respond_to blocks.
This pull request first removes the comments from the scaffold controller (people should know this already, and if not they can learn from the Routing and Getting Started guides). That's the simple part.
The second commit here removes the ugly respond_to blocks, replacing it with a controller-level respond_to call, which is exactly how the respond_to blocks act. Well, at least as far as our testing goes.
Two more things for further concern.
First is that the scaffold generator generates functional tests for the HTML component that's generated, but doesn't generate XML tests. Is there any particular reason for this?
Second: Is there any particular reason why these controllers respond to XML rather than JSON these days? I would think that JSON is the preferred API respond format. This could just be a case of extreme bikeshedding though.
+1 for the Scaffold generator using JSON and not XML
This discussion appears from time to time. The default scaffold is mainly a learning tool. respond_with does a lot implicitly and would be harder for a beginner to understand, that's we still using respond_to. XML or JSON does not really matter, the point here is to show developers that there are to main kinds of formats: navigational and api. Changing XML for JSON at this point, would also "deprecate" all tutorials and books, which is not worth considering the default scaffold is just a learning tool anyway.
If you want to change scaffold, you can create your own generator and customize your app to use, at least this is what I did with the responders gem (http://github.com/plataformatec/responders).
Ah, good to see the Rails team is now concerned with the deprecation of books. This makes me feel safer.
Thanks for the reply & feedback José.
Just to make it explicit: I don't think we should hold back adding/changing a feature in Rails to avoid deprecating books/tutorials/blog posts. However, given the default scaffold is exactly a learning tool and is one of the things that is first covered, I don't think trading XML by JSON is a worth change in a 3.0 to 3.1 release. A counter-example is exactly the changes the scaffold views had from 2.3 to 3.0.
The problem for me at least is that it seems like a huge number of people are using scaffold generator as a day to day tool in their work. With a room of 20 rails devs at railscamp we had a decent quantity who expressed surprise when Ryan pointed out that you shouldn't be using the current generators as a day to day development tool.
Certainly my experience shows that people are using it in business quite a lot. I've seen quite a few cases where the explicit commenting of routes above the methods has become the documentation standard throughout the app.
It's my belief that it's being used pretty heavily as something other than a learning tool, but I can't really prove it.
Hey Breccan, thanks for the pull request. However, wrong usage does not justify the change. For example, I have seen my share of people using MVC wrongly and there is nothing we can do besides instructing people to do the proper thing. The tools to extend scaffold beyond a learning tool are available, we just need to instruct people to use them properly.