O'Reilly logo

Crafting Rails 4 Applications, 2nd Edition by José Valim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6Writing DRY Controllers with Responders

  • Rails responders and the respond_with method

  • Rails generators’ template customization

Rails’s scaffold generator is a great tool to help us prototype a new application. Its flexibility lets us swap the default template engine, test framework, and object-relational mapper (ORM) for our favorite options, ensuring we are productive regardless of the tools we choose. The only problem with scaffolding is that the generated controllers are still a little bit verbose, and we end up with a lot of behavior duplicated across different controllers. For example, here are the create and destroy actions similar to what would be generated by the scaffold generator when invoked with a name attribute:

 
class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required