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]
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?
Right now I have some controllers hacked with plist_create actions and
I access the raw POST data in env. I’d like it to look like this:
def create
This of course requires something under the covers to recognize
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.
Regarding the way you suggest handling rendering the plist, that’s the
plan. My example was create, and the response was arbitrary.
My question is still - where does the xml get parsed? When something
is posted to *.xml something is turning it into a name/value list, and
I need to do that from a plist instead of whatever xml format it
transforms by default.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.