开发者

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

开发者 https://www.devze.com 2022-12-26 11:42 出处:网络
I would like to create a custom render as specified in title. For instance, I have my controller: class MyController < ApplicationController

I would like to create a custom render as specified in title.

For instance, I have my 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 need to make it work?

Thanks in advance!

UPDATE

I want something like in here. So I replaced the @objs with a method but it didn't work either (the method wasn't called).

Obs: I register the mime type at config/initializers/mime_types.rb.


From railsapi.com:

"If you need to use a MIME type which isn’t supported by default, you can register your own handlers in environment.rb as follows."

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

精彩评论

暂无评论...
验证码 换一张
取 消