Alex wrote:> I want to add a different xml format, plist in this case, to my
> controller for the create action. Using the default scaffold, I can
> handle the standard AR format. I''d like to be able to have a post
to:
>
> POST foos/create.plist
> [plist formatted object]
> respond_to do |format|
> format.plist { render :xml => some_response.to_plist }
> end
> end
It sounds to me that you''re thinking in the wrong MVC layer. I would
handle the plist format in a similar way as to_json by extending the
model objects with a to_plist method. Then you simply need to register a
mime-type for plist format and so something like:
> respond_to do |format|
> format.plist { render :xml => my_model_object.to_plist }
> end
> That means I need to parse the incoming plist and turn it into an AR
> object. That''s not hard, but I''m not sure where to do
it, how to
> route the .plist request, etc. Do I need to create a new content-type
> handler? Where do I access the POST data?
I''m not quite expert enough to know for sure if this will work, but you
might look into adding your plist parsing as Rack middle-ware. This
would be similar to the Rack middle-ware that handles the JSON parsing.
Check out http://railslab.newrelic.com/2009/06/05/episode-14-rack-metal
for information on how you might approach this.
--
Posted via http://www.ruby-forum.com/.