Skip to content
dennisbulgatz edited this page Apr 20, 2011 · 10 revisions

By default active scaffold responds to the html, json, js, xml, and yaml mime types. If you want to override one of these responses you can override the <action>_respond_to_<format> method in the controller:

def show_respond_to_html
  render :action => :show, :layout => 'main'
end

def list_respond_to_xml
     render :xml => @records.to_xml(:except => [:full_definition, :cradle_item_type_id], :include => [:cradle_item_type]) 
end

If you need to add a custom mime type you can do it in one of two ways.

# to add a mime type to all actions
active_scaffold do |config|
  config.formats << :pdf
end

# to add it to only one action
active_scaffold do |config|
  config.show.formats << :pdf
end

So now your controller or action will respond to that format. Now you need to hook into the response type for that action.

def show_respond_to_pdf
  #render whatever you want here
end

List action will load records in @records variable, other actions will load the record in @record variable

Clone this wiki locally