respond_to:    and  MIME Type.
--------------------------------------------------------
 
respond_to is a method of rails that defines different formats that your actions, well , respond to.
And the formate of file is maintained in rails mime_type.
#require 'action_controller/mine_types'
#actionpack/lib/actioncontroller/mimetypes.rb
and if you need to use a MIME type which isn't supported by default, you can register your own handler in config/initializers/mime_types.rb
MIME::Type.register "image/jpg", :jpg
And Respond to also allows you to specify a common block for different formats by using any:
Now! one thing is important to notice the render file extension should be like this..
according to this block .. on index action it will be render two file ,
1st -- index.xml.erb, and 2nd is index.json.erb .
  
--------------------------------------------------------
respond_to is a method of rails that defines different formats that your actions, well , respond to.
And the formate of file is maintained in rails mime_type.
#require 'action_controller/mine_types'
#actionpack/lib/actioncontroller/mimetypes.rb
and if you need to use a MIME type which isn't supported by default, you can register your own handler in config/initializers/mime_types.rb
MIME::Type.register "image/jpg", :jpg
And Respond to also allows you to specify a common block for different formats by using any:
def index
  @people = Person.all
  respond_to do |format|
    format.html
    format.any(:xml, :json) { render request.format.to_sym => @people }
  end
endNow! one thing is important to notice the render file extension should be like this..
according to this block .. on index action it will be render two file ,
1st -- index.xml.erb, and 2nd is index.json.erb .
 
No comments:
Post a Comment