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.

2 Answers 2

6

You can register new ones like this (place this in your config/environment.rb, one of the config/environments/*.rb files or in a file under config/initializers):

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]
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.