We build Web & Mobile Applications.

< All Articles

Shorthand alternative for respond_to

If you have a simple respond_to block in your controller that looks like this:

respond_to do |format|
  format.html
  format.xml
end

You can use this alternate syntax and save a few keystrokes..

respond_to(:html, :xml)

Ok so it may not give you a huge performance boost, but if you’re obsessed with reducing the size of your code, this is a nice way to make a saving!

Updated on 16 July 2015
First published by Chris Anderton on 04 April 2009
© TheWebFellas Limited 2016
"Shorthand alternative for respond_to" by Chris Anderton at TheWebFellas is licensed under a Creative Commons Attribution 4.0 International License.