views:

1172

answers:

2

So here is what I have:

  def index
    @profiles = Profile.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @profiles }
      format.json  { render :json => @profiles }
    end
  end

I would like to add rss, atom and possibly some custom ones such as one that returns the image for the profile.

A: 

You can use the resource_feeder built into rails to do this:

script/plugin install simply_helpful
script/plugin install resource_feeder

In the profile controller:

def index
  @profiles = Profile.all

  options = { :feed => { :title => "All Profiles" },
                    :item => { :title => :name } }

  respond_to do |format|
    format.html
    format.xml { render :xml => @profiles
    format.json { render :json => @profiles
    format.rss { render_rss_feed_for @profiles, options }
    format.atom { render_atom_feed_for @profiles, options }
  end

end

iano
+3  A: 

You can register new ones like this:

Mime::Type.register 'application/pdf', :pdf
Mime::Type.register 'application/vnd.ms-excel', :xls

As for the default ones:

>> Mime::SET.map(&:to_sym)
=> [:all, :text, :html, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :xls]
derfred