How do I override the render to create a custom render: my_format => argument in rails 2.3 (.5)?

I would like to create a custom renderer listed in the title.

For example, I have a controller:

class MyController < ApplicationController
  def index
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @objs }
    end
  end
end

      

but I would like something like this:

class MyController < ApplicationController
  def index
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @objs }
      format.my_format  { render :my_format => @objs }
    end
  end
end

      

Is it possible? What are the steps I have to take in order for them to work?

Thanks in advance!

UPDATE

I need something like here . So I replaced @objs with a method, but it didn't work either (no method was called).

Obs: I am registering the mime type in config / initializers / mime_types.rb.

+2


a source to share


1 answer


From railsapi.com :

"If you need to use a MIME type that is not supported by default, you can register your own handlers in environment.rb as follows."



  Mime::Type.register "image/jpg", :jpg

      

+3


a source







All Articles