Saturday 14 February 2015

Use of respond to in rails 4




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 and also Json. 

By using respond to in rails we present the data or we sending the data according to client requirement by this method.

Example : 

 respond_to do |format|

     format.html { redirect_to(person_list_url}     
     format.xml  {render :xml => @modelname }
     format.json {render :json => @modelname.as_json}
     format.js {}

end


Here we send data in multiple format according to client requirement.  but in html format we redirect the url for html request for a particular page..in html format.

For more information go on =>  respond_to in rails 4 .








No comments:

Salesforce CRM vs. Zoho: A Comparative Analysis

Introduction: Selecting the right customer relationship management (CRM) software is crucial for businesses seeking to streamline their sal...