respond_to do |format|
format.html
format.xml { render :xml => @mah_blogz }
end
respond_to do |format|
format.js
end
Whats this respond_to
, format.html
, format.xml
and format.js
. Whats the purpose, How they work.
respond_to do |format|
format.html
format.xml { render :xml => @mah_blogz }
end
respond_to do |format|
format.js
end
Whats this respond_to
, format.html
, format.xml
and format.js
. Whats the purpose, How they work.
It is a way for you to serve an, e.g., XML representation instead of an HTML one. Useful if you want to create a client not using HTML.
Here's the link to the documentation
http://api.rubyonrails.org/classes/ActionController/MimeResponds/InstanceMethods.html#M000386
Its a way of responding to the client based on what they are asking for, if the client asks for HTML, Rails will send back HTML to the client, if they ask for XML then XML.